diff options
Diffstat (limited to 'src/libunixonacid/unixmessage_put.c')
-rw-r--r-- | src/libunixonacid/unixmessage_put.c | 32 |
1 files changed, 12 insertions, 20 deletions
diff --git a/src/libunixonacid/unixmessage_put.c b/src/libunixonacid/unixmessage_put.c index 43091c9..d9fe306 100644 --- a/src/libunixonacid/unixmessage_put.c +++ b/src/libunixonacid/unixmessage_put.c @@ -4,10 +4,10 @@ #ifdef SKALIBS_HASANCILAUTOCLOSE #include <unistd.h> #endif +#include <string.h> #include <errno.h> #include <skalibs/bitarray.h> -#include <skalibs/bytestr.h> -#include <skalibs/diuint.h> +#include <skalibs/disize.h> #include <skalibs/error.h> #include <skalibs/stralloc.h> #include <skalibs/genalloc.h> @@ -16,7 +16,7 @@ static inline int copyfds (char *s, int const *fds, unsigned int n, unsigned char const *bits, unixmessage_sender_closecb_func_t_ref closecb, void *closecbdata) { - register unsigned int i = 0 ; + unsigned int i = 0 ; for (; i < n ; i++) { int fd = fds[i] ; @@ -32,7 +32,7 @@ static inline int copyfds (char *s, int const *fds, unsigned int n, unsigned cha while (i--) { s -= sizeof(int) ; - byte_copy((char *)fd, sizeof(int), s) ; + memcpy((char *)fd, s, sizeof(int)) ; if (fd >= 0) (*closecb)(fd, closecbdata) ; } errno = e ; @@ -40,46 +40,38 @@ static inline int copyfds (char *s, int const *fds, unsigned int n, unsigned cha } } #endif - byte_copy(s, sizeof(int), (char const *)&fd) ; + memcpy(s, (char const *)&fd, sizeof(int)) ; s += sizeof(int) ; } return 1 ; } -static int reserve_and_copy (unixmessage_sender_t *b, unsigned int len, int const *fds, unsigned int nfds, unsigned char const *bits) +static int reserve_and_copy (unixmessage_sender_t *b, size_t len, int const *fds, unsigned int nfds, unsigned char const *bits) { - diuint cur = { .left = b->data.len, .right = genalloc_len(int, &b->fds) } ; + disize cur = { .left = b->data.len, .right = genalloc_len(int, &b->fds) } ; if (len > UNIXMESSAGE_MAXSIZE || nfds > UNIXMESSAGE_MAXFDS) return (errno = EPROTO, 0) ; - if (!genalloc_readyplus(diuint, &b->offsets, 1) + if (!genalloc_readyplus(disize, &b->offsets, 1) || !genalloc_readyplus(int, &b->fds, nfds) || !stralloc_readyplus(&b->data, len)) return 0 ; if (!copyfds(b->fds.s + b->fds.len, fds, nfds, bits, b->closecb, b->closecbdata)) return 0 ; genalloc_setlen(int, &b->fds, cur.right + nfds) ; - byte_copy(b->offsets.s + b->offsets.len, sizeof(diuint), (char const *)&cur) ; - b->offsets.len += sizeof(diuint) ; - return 1 ; + return genalloc_append(disize, &b->offsets, &cur) ; } int unixmessage_put_and_close (unixmessage_sender_t *b, unixmessage_t const *m, unsigned char const *bits) { if (!reserve_and_copy(b, m->len, m->fds, m->nfds, bits)) return 0 ; - byte_copy(b->data.s + b->data.len, m->len, m->s) ; + memmove(b->data.s + b->data.len, m->s, m->len) ; b->data.len += m->len ; return 1 ; } int unixmessage_putv_and_close (unixmessage_sender_t *b, unixmessage_v_t const *m, unsigned char const *bits) { - unsigned int len = 0 ; - register unsigned int i = 0 ; - for (; i < m->vlen ; i++) len += m->v[i].len ; + size_t len = siovec_len(m->v, m->vlen) ; if (!reserve_and_copy(b, len, m->fds, m->nfds, bits)) return 0 ; - for (i = 0 ; i < m->vlen ; i++) - { - byte_copy(b->data.s + b->data.len, m->v[i].len, m->v[i].s) ; - b->data.len += m->v[i].len ; - } + siovec_gather(m->v, m->vlen, b->data.s + b->data.len, len) ; return 1 ; } |