diff options
-rw-r--r-- | src/libstddjb/siovec_gather.c | 4 | ||||
-rw-r--r-- | src/libunixonacid/unixmessage_bits_closeall.c | 11 | ||||
-rw-r--r-- | src/libunixonacid/unixmessage_bits_closenone.c | 2 | ||||
-rw-r--r-- | src/libunixonacid/unixmessage_put.c | 19 |
4 files changed, 21 insertions, 15 deletions
diff --git a/src/libstddjb/siovec_gather.c b/src/libstddjb/siovec_gather.c index 4288141..aa73677 100644 --- a/src/libstddjb/siovec_gather.c +++ b/src/libstddjb/siovec_gather.c @@ -2,13 +2,13 @@ #include <sys/uio.h> #include <string.h> + #include <skalibs/siovec.h> size_t siovec_gather (struct iovec const *v, unsigned int n, char *s, size_t max) { size_t w = 0 ; - unsigned int i = 0 ; - for (; i < n && w < max ; i++) + for (unsigned int i = 0 ; i < n && w < max ; i++) { size_t len = v[i].iov_len ; if (len > max - w) len = max - w ; diff --git a/src/libunixonacid/unixmessage_bits_closeall.c b/src/libunixonacid/unixmessage_bits_closeall.c index 32d77d6..54c79b2 100644 --- a/src/libunixonacid/unixmessage_bits_closeall.c +++ b/src/libunixonacid/unixmessage_bits_closeall.c @@ -3,5 +3,14 @@ #include <skalibs/bitarray.h> #include <skalibs/unixmessage.h> -static unsigned char const unixmessage_bits_closeall_[bitarray_div8(UNIXMESSAGE_MAXFDS)] = "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" ; +static unsigned char const unixmessage_bits_closeall_[bitarray_div8(UNIXMESSAGE_MAXFDS)] = +"\377" +// "\377" "\377" // 253 = 255 & ~2 +"\377" "\377" "\377" "\377" +"\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" +"\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" +"\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" +"\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" +"\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" + ; unsigned char const *const unixmessage_bits_closeall = unixmessage_bits_closeall_ ; diff --git a/src/libunixonacid/unixmessage_bits_closenone.c b/src/libunixonacid/unixmessage_bits_closenone.c index bacbc6a..5ed3cc6 100644 --- a/src/libunixonacid/unixmessage_bits_closenone.c +++ b/src/libunixonacid/unixmessage_bits_closenone.c @@ -3,5 +3,5 @@ #include <skalibs/bitarray.h> #include <skalibs/unixmessage.h> -static unsigned char const unixmessage_bits_closenone_[bitarray_div8(UNIXMESSAGE_MAXFDS)] = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" ; +static unsigned char const unixmessage_bits_closenone_[bitarray_div8(UNIXMESSAGE_MAXFDS)] = { 0 } ; unsigned char const *const unixmessage_bits_closenone = unixmessage_bits_closenone_ ; diff --git a/src/libunixonacid/unixmessage_put.c b/src/libunixonacid/unixmessage_put.c index a41c5c0..59feed3 100644 --- a/src/libunixonacid/unixmessage_put.c +++ b/src/libunixonacid/unixmessage_put.c @@ -11,16 +11,14 @@ #include <skalibs/unixmessage.h> #include <skalibs/posixishard.h> -static inline int copyfds (char *s, int const *fds, unsigned int n, unsigned char const *bits, unixmessage_sender_closecb_func_ref closecb, void *closecbdata) +static inline int copyfds (int *dst, int const *src, unsigned int n, unsigned char const *bits) { - unsigned int i = 0 ; - for (; i < n ; i++) + for (unsigned int i = 0 ; i < n ; i++) { - int fd = fds[i] ; - if (fd < 0) return (errno = EINVAL, -1) ; + int fd = src[i] ; + if (fd < 0) return (errno = EINVAL, 0) ; if (bitarray_peek(bits, i)) fd = - fd - 1 ; - memcpy(s, (char const *)&fd, sizeof(int)) ; - s += sizeof(int) ; + dst[i] = fd ; } return 1 ; } @@ -28,15 +26,14 @@ static inline int copyfds (char *s, int const *fds, unsigned int n, unsigned cha static int reserve_and_copy (unixmessage_sender *b, size_t len, int const *fds, unsigned int nfds, unsigned char const *bits) { disize cur = { .left = b->data.len, .right = genalloc_len(int, &b->fds) } ; - if (len > UNIXMESSAGE_MAXSIZE || nfds > UNIXMESSAGE_MAXFDS) - return (errno = EPROTO, 0) ; + if (len > UNIXMESSAGE_MAXSIZE || nfds > UNIXMESSAGE_MAXFDS) return (errno = EPROTO, 0) ; 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 ; + if (!copyfds(genalloc_s(int, &b->fds) + cur.right, fds, nfds, bits)) return 0 ; genalloc_setlen(int, &b->fds, cur.right + nfds) ; - return genalloc_append(disize, &b->offsets, &cur) ; + return genalloc_catb(disize, &b->offsets, &cur, 1) ; } int unixmessage_put_and_close (unixmessage_sender *b, unixmessage const *m, unsigned char const *bits) |