diff options
Diffstat (limited to 'src/libstddjb')
118 files changed, 475 insertions, 946 deletions
diff --git a/src/libstddjb/absolutepath_tmp.c b/src/libstddjb/absolutepath_tmp.c index 3d3c2b1..b0e1e07 100644 --- a/src/libstddjb/absolutepath_tmp.c +++ b/src/libstddjb/absolutepath_tmp.c @@ -1,5 +1,7 @@ /* ISC license. */ +/* MT-unsafe (because of chdir) */ + #include <sys/types.h> #include <unistd.h> #include <errno.h> @@ -52,7 +54,7 @@ int sarealpath_tmp (stralloc *sa, char const *path, stralloc *tmp) err: { - register int e = errno ; + int e = errno ; tmp->len = tmpbase ; fd_chdir(fdhere) ; fd_close(fdhere) ; diff --git a/src/libstddjb/allread.c b/src/libstddjb/allread.c index a33b650..3fdd4ea 100644 --- a/src/libstddjb/allread.c +++ b/src/libstddjb/allread.c @@ -5,5 +5,5 @@ size_t allread (int fd, char *buf, size_t len) { - return allreadwrite(&fd_readv, fd, buf, len) ; + return allreadwrite(&fd_read, fd, buf, len) ; } diff --git a/src/libstddjb/allreadwritev.c b/src/libstddjb/allreadwritev.c index 2b06ac7..5ba3837 100644 --- a/src/libstddjb/allreadwritev.c +++ b/src/libstddjb/allreadwritev.c @@ -9,12 +9,12 @@ size_t allreadwritev (iovfunc_t_ref op, int fd, struct iovec const *v, unsigned int vlen) { size_t written = 0 ; - struct iovec vv[vlen] ; - unsigned int i = 0 ; - for (; i < vlen ; i++) vv[i] = v[i] ; + struct iovec vv[vlen ? vlen : 1] ; + unsigned int i = vlen ; + while (i--) vv[i] = v[i] ; while (siovec_len(vv, vlen)) { - register ssize_t w = (*op)(fd, vv, vlen) ; + ssize_t w = (*op)(fd, vv, vlen) ; if (w <= 0) break ; w = siovec_seek(vv, vlen, w) ; written += w ; diff --git a/src/libstddjb/allwrite.c b/src/libstddjb/allwrite.c index f465eb4..200227d 100644 --- a/src/libstddjb/allwrite.c +++ b/src/libstddjb/allwrite.c @@ -1,5 +1,7 @@ /* ISC license. */ +#include <sys/types.h> +#include <skalibs/functypes.h> #include <skalibs/allreadwrite.h> size_t allwrite (int fd, char const *buf, size_t len) diff --git a/src/libstddjb/basename.c b/src/libstddjb/basename.c deleted file mode 100644 index 4eb4080..0000000 --- a/src/libstddjb/basename.c +++ /dev/null @@ -1,19 +0,0 @@ -/* ISC license. */ - -/* MT-unsafe */ - -#include <skalibs/bytestr.h> -#include <skalibs/stralloc.h> -#include <skalibs/djbunix.h> - -char *basename (char *s) -{ - static stralloc basename_sa = STRALLOC_ZERO ; - static char dot0[2] = "." ; - char *dot = dot0 ; - if (!s) return dot ; - basename_sa.len = 0 ; - if (!sabasename(&basename_sa, s, str_len(s))) return 0 ; - if (!stralloc_0(&basename_sa)) return 0 ; - return basename_sa.s ; -} diff --git a/src/libstddjb/bufalloc_init.c b/src/libstddjb/bufalloc_init.c index d6a89da..c538bc1 100644 --- a/src/libstddjb/bufalloc_init.c +++ b/src/libstddjb/bufalloc_init.c @@ -4,7 +4,7 @@ #include <skalibs/stralloc.h> #include <skalibs/bufalloc.h> -void bufalloc_init (bufalloc *ba, int (*op)(int, char const *, size_t), int fd) +void bufalloc_init (bufalloc *ba, ssize_t (*op)(int, char const *, size_t), int fd) { ba->x = stralloc_zero ; ba->op = op ; diff --git a/src/libstddjb/buffer_fill.c b/src/libstddjb/buffer_fill.c index 9899be1..b3a1bf2 100644 --- a/src/libstddjb/buffer_fill.c +++ b/src/libstddjb/buffer_fill.c @@ -1,12 +1,14 @@ /* ISC license. */ +#include <sys/types.h> +#include <sys/uio.h> #include <errno.h> #include <skalibs/buffer.h> -int buffer_fill (buffer *b) +ssize_t buffer_fill (buffer *b) { - siovec_t v[2] ; - register int r ; + struct iovec v[2] ; + ssize_t r ; if (buffer_isfull(b)) return (errno = ENOBUFS, -1) ; buffer_wpeek(b, v) ; r = (*b->op)(b->fd, v, 2) ; diff --git a/src/libstddjb/buffer_flush.c b/src/libstddjb/buffer_flush.c index 46512fc..3249a11 100644 --- a/src/libstddjb/buffer_flush.c +++ b/src/libstddjb/buffer_flush.c @@ -1,17 +1,18 @@ /* ISC license. */ +#include <sys/types.h> +#include <sys/uio.h> #include <skalibs/cbuffer.h> -#include <skalibs/siovec.h> #include <skalibs/buffer.h> int buffer_flush (buffer *b) { for (;;) { - siovec_t v[2] ; - register int r ; + struct iovec v[2] ; + ssize_t r ; buffer_rpeek(b, v) ; - if (!v[0].len && !v[1].len) break ; + if (!v[0].iov_len && !v[1].iov_len) break ; r = (*b->op)(b->fd, v, 2) ; if (r <= 0) return 0 ; cbuffer_RSEEK(&b->c, r) ; diff --git a/src/libstddjb/buffer_get.c b/src/libstddjb/buffer_get.c index ff67a06..0263f87 100644 --- a/src/libstddjb/buffer_get.c +++ b/src/libstddjb/buffer_get.c @@ -1,12 +1,13 @@ /* ISC license. */ +#include <sys/types.h> #include <errno.h> #include <skalibs/buffer.h> -int buffer_get (buffer *b, char *s, unsigned int len) +ssize_t buffer_get (buffer *b, char *s, size_t len) { - unsigned int w = 0 ; + size_t w = 0 ; register int r = buffer_getall(b, s, len, &w) ; - return r == -1 ? errno == EPIPE ? (errno = 0, (int)w) : -1 : - !r ? (errno = EWOULDBLOCK, -1) : (int)w ; + return r == -1 ? errno == EPIPE ? (errno = 0, (ssize_t)w) : -1 : + !r ? (errno = EWOULDBLOCK, -1) : (ssize_t)w ; } diff --git a/src/libstddjb/buffer_getall.c b/src/libstddjb/buffer_getall.c index dc0e115..dca9e3b 100644 --- a/src/libstddjb/buffer_getall.c +++ b/src/libstddjb/buffer_getall.c @@ -1,15 +1,16 @@ /* ISC license. */ +#include <sys/types.h> #include <errno.h> #include <skalibs/allreadwrite.h> #include <skalibs/buffer.h> -int buffer_getall (buffer *b, char *buf, unsigned int len, unsigned int *w) +int buffer_getall (buffer *b, char *buf, size_t len, size_t *w) { if (*w > len) return (errno = EINVAL, -1) ; for (;;) { - register int r ; + ssize_t r ; *w += buffer_getnofill(b, buf + *w, len - *w) ; if (*w >= len) break ; r = sanitize_read(buffer_fill(b)) ; diff --git a/src/libstddjb/buffer_getallnf.c b/src/libstddjb/buffer_getallnf.c index be46196..9ad0036 100644 --- a/src/libstddjb/buffer_getallnf.c +++ b/src/libstddjb/buffer_getallnf.c @@ -1,11 +1,12 @@ /* ISC license. */ +#include <sys/types.h> #include <errno.h> #include <skalibs/buffer.h> -int buffer_getallnofill (buffer *b, char *s, unsigned int len) +int buffer_getallnofill (buffer *b, char *s, size_t len) { - register unsigned int r = buffer_getnofill(b, s, len) ; + size_t r = buffer_getnofill(b, s, len) ; if (r < len) { buffer_unget(b, r) ; diff --git a/src/libstddjb/buffer_getlen.c b/src/libstddjb/buffer_getlen.c index 73289a7..47ff472 100644 --- a/src/libstddjb/buffer_getlen.c +++ b/src/libstddjb/buffer_getlen.c @@ -1,8 +1,9 @@ /* ISC license. */ +#include <sys/types.h> #include <skalibs/buffer.h> -unsigned int buffer_getlen (buffer const *b) +size_t buffer_getlen (buffer const *b) { return buffer_len(b) ; } diff --git a/src/libstddjb/buffer_getv.c b/src/libstddjb/buffer_getv.c index b3d237e..358de01 100644 --- a/src/libstddjb/buffer_getv.c +++ b/src/libstddjb/buffer_getv.c @@ -1,12 +1,13 @@ /* ISC license. */ +#include <sys/types.h> +#include <sys/uio.h> #include <skalibs/allreadwrite.h> #include <skalibs/buffer.h> -#include <skalibs/siovec.h> -int buffer_getv (buffer *b, siovec_t const *v, unsigned int n) +ssize_t buffer_getv (buffer *b, struct iovec const *v, unsigned int n) { - unsigned int w = 0 ; - register int r = unsanitize_read(buffer_getvall(b, v, n, &w)) ; + size_t w = 0 ; + ssize_t r = unsanitize_read(buffer_getvall(b, v, n, &w)) ; return r <= 0 ? r : w ; } diff --git a/src/libstddjb/buffer_getvall.c b/src/libstddjb/buffer_getvall.c index e34c547..ba2dfae 100644 --- a/src/libstddjb/buffer_getvall.c +++ b/src/libstddjb/buffer_getvall.c @@ -1,14 +1,16 @@ /* ISC license. */ +#include <sys/types.h> +#include <sys/uio.h> #include <errno.h> #include <skalibs/allreadwrite.h> #include <skalibs/buffer.h> #include <skalibs/siovec.h> -int buffer_getvall (buffer *b, siovec_t const *v, unsigned int n, unsigned int *written) +int buffer_getvall (buffer *b, struct iovec const *v, unsigned int n, size_t *written) { - unsigned int len = siovec_len(v, n) ; - siovec_t vv[n] ; + size_t len = siovec_len(v, n) ; + struct iovec vv[n ? n : 1] ; if (*written > len) return (errno = EINVAL, -1) ; { register unsigned int i = n ; @@ -17,8 +19,8 @@ int buffer_getvall (buffer *b, siovec_t const *v, unsigned int n, unsigned int * siovec_seek(vv, n, *written) ; for (;;) { - register int r ; - unsigned int w = buffer_getvnofill(b, vv, n) ; + ssize_t r ; + size_t w = buffer_getvnofill(b, vv, n) ; *written += w ; if (*written >= len) break ; siovec_seek(vv, n, w) ; @@ -27,4 +29,3 @@ int buffer_getvall (buffer *b, siovec_t const *v, unsigned int n, unsigned int * } return 1 ; } - diff --git a/src/libstddjb/buffer_getvallnf.c b/src/libstddjb/buffer_getvallnf.c index 15f6c3d..e0e2e5d 100644 --- a/src/libstddjb/buffer_getvallnf.c +++ b/src/libstddjb/buffer_getvallnf.c @@ -1,12 +1,14 @@ /* ISC license. */ +#include <sys/types.h> +#include <sys/uio.h> #include <errno.h> -#include <skalibs/buffer.h> #include <skalibs/siovec.h> +#include <skalibs/buffer.h> -int buffer_getvallnofill (buffer *b, siovec_t const *v, unsigned int n) +int buffer_getvallnofill (buffer *b, struct iovec const *v, unsigned int n) { - register unsigned int r = buffer_getvnofill(b, v, n) ; + size_t r = buffer_getvnofill(b, v, n) ; if (r < siovec_len(v, n)) { buffer_unget(b, r) ; diff --git a/src/libstddjb/buffer_init.c b/src/libstddjb/buffer_init.c index fac648a..27fd4e5 100644 --- a/src/libstddjb/buffer_init.c +++ b/src/libstddjb/buffer_init.c @@ -1,11 +1,12 @@ /* ISC license. */ +#include <sys/types.h> #include <errno.h> #include <skalibs/cbuffer.h> #include <skalibs/functypes.h> #include <skalibs/buffer.h> -int buffer_init (buffer *b, iovfunc_t_ref op, int fd, char *s, unsigned int len) +int buffer_init (buffer *b, iovfunc_t_ref op, int fd, char *s, size_t len) { if (!cbuffer_init(&b->c, s, len)) return 0 ; b->fd = fd ; diff --git a/src/libstddjb/buffer_put.c b/src/libstddjb/buffer_put.c index 56baaa7..5e1fb89 100644 --- a/src/libstddjb/buffer_put.c +++ b/src/libstddjb/buffer_put.c @@ -1,10 +1,11 @@ /* ISC license. */ +#include <sys/types.h> #include <skalibs/buffer.h> -int buffer_put (buffer *b, char const *s, unsigned int len) +ssize_t buffer_put (buffer *b, char const *s, size_t len) { - unsigned int w = 0 ; + size_t w = 0 ; if (!buffer_putall(b, s, len, &w)) return -1 ; - return (int)w ; + return (ssize_t)w ; } diff --git a/src/libstddjb/buffer_putall.c b/src/libstddjb/buffer_putall.c index 16facc2..f65b73e 100644 --- a/src/libstddjb/buffer_putall.c +++ b/src/libstddjb/buffer_putall.c @@ -1,9 +1,10 @@ /* ISC license. */ +#include <sys/types.h> #include <errno.h> #include <skalibs/buffer.h> -int buffer_putall (buffer *b, char const *s, unsigned int len, unsigned int *written) +int buffer_putall (buffer *b, char const *s, size_t len, size_t *written) { if (*written > len) return (errno = EINVAL, 0) ; for (;;) diff --git a/src/libstddjb/buffer_putallnf.c b/src/libstddjb/buffer_putallnf.c index 1cf3c5e..8ee5c54 100644 --- a/src/libstddjb/buffer_putallnf.c +++ b/src/libstddjb/buffer_putallnf.c @@ -1,11 +1,12 @@ /* ISC license. */ +#include <sys/types.h> #include <errno.h> #include <skalibs/buffer.h> -int buffer_putallnoflush (buffer *b, char const *s, unsigned int len) +int buffer_putallnoflush (buffer *b, char const *s, size_t len) { - register unsigned int r = buffer_putnoflush(b, s, len) ; + ssize_t r = buffer_putnoflush(b, s, len) ; if (r < len) { buffer_unput(b, r) ; diff --git a/src/libstddjb/buffer_putflush.c b/src/libstddjb/buffer_putflush.c index 609d88b..0443180 100644 --- a/src/libstddjb/buffer_putflush.c +++ b/src/libstddjb/buffer_putflush.c @@ -1,10 +1,11 @@ /* ISC license. */ +#include <sys/types.h> #include <skalibs/buffer.h> -int buffer_putflush (buffer *b, char const *s, unsigned int len) +ssize_t buffer_putflush (buffer *b, char const *s, size_t len) { - int r = buffer_put(b, s, len) ; + ssize_t r = buffer_put(b, s, len) ; if (r < 0) return -1 ; if (!buffer_flush(b)) return -1 ; return r ; diff --git a/src/libstddjb/buffer_puts.c b/src/libstddjb/buffer_puts.c index aaaac2e..84acca8 100644 --- a/src/libstddjb/buffer_puts.c +++ b/src/libstddjb/buffer_puts.c @@ -1,9 +1,10 @@ /* ISC license. */ -#include <skalibs/bytestr.h> +#include <sys/types.h> +#include <string.h> #include <skalibs/buffer.h> -int buffer_puts (buffer *b, char const *s) +ssize_t buffer_puts (buffer *b, char const *s) { - return buffer_put(b, s, str_len(s)) ; + return buffer_put(b, s, strlen(s)) ; } diff --git a/src/libstddjb/buffer_putsall.c b/src/libstddjb/buffer_putsall.c index dbd306c..382f74b 100644 --- a/src/libstddjb/buffer_putsall.c +++ b/src/libstddjb/buffer_putsall.c @@ -1,9 +1,10 @@ /* ISC license. */ -#include <skalibs/bytestr.h> +#include <sys/types.h> +#include <string.h> #include <skalibs/buffer.h> -int buffer_putsall (buffer *b, char const *s, unsigned int *w) +int buffer_putsall (buffer *b, char const *s, size_t *w) { - return buffer_putall(b, s, str_len(s), w) ; + return buffer_putall(b, s, strlen(s), w) ; } diff --git a/src/libstddjb/buffer_putsallflush.c b/src/libstddjb/buffer_putsallflush.c index fa4c98c..a63cca7 100644 --- a/src/libstddjb/buffer_putsallflush.c +++ b/src/libstddjb/buffer_putsallflush.c @@ -1,9 +1,10 @@ /* ISC license. */ -#include <skalibs/bytestr.h> +#include <sys/types.h> +#include <string.h> #include <skalibs/buffer.h> -int buffer_putsallflush (buffer *b, char const *s, unsigned int *w) +int buffer_putsallflush (buffer *b, char const *s, size_t *w) { - return buffer_putallflush(b, s, str_len(s), w) ; + return buffer_putallflush(b, s, strlen(s), w) ; } diff --git a/src/libstddjb/buffer_putsallnoflush.c b/src/libstddjb/buffer_putsallnoflush.c index 0056cb4..e0d7e36 100644 --- a/src/libstddjb/buffer_putsallnoflush.c +++ b/src/libstddjb/buffer_putsallnoflush.c @@ -1,9 +1,9 @@ /* ISC license. */ -#include <skalibs/bytestr.h> +#include <string.h> #include <skalibs/buffer.h> int buffer_putsallnoflush (buffer *b, char const *s) { - return buffer_putallnoflush(b, s, str_len(s)) ; + return buffer_putallnoflush(b, s, strlen(s)) ; } diff --git a/src/libstddjb/buffer_putsflush.c b/src/libstddjb/buffer_putsflush.c index 4be4c34..fc54a3e 100644 --- a/src/libstddjb/buffer_putsflush.c +++ b/src/libstddjb/buffer_putsflush.c @@ -1,9 +1,10 @@ /* ISC license. */ -#include <skalibs/bytestr.h> +#include <sys/types.h> +#include <string.h> #include <skalibs/buffer.h> -int buffer_putsflush (buffer *b, char const *s) +ssize_t buffer_putsflush (buffer *b, char const *s) { - return buffer_putflush(b, s, str_len(s)) ; + return buffer_putflush(b, s, strlen(s)) ; } diff --git a/src/libstddjb/buffer_putsnoflush.c b/src/libstddjb/buffer_putsnoflush.c index ad6b372..06d12d1 100644 --- a/src/libstddjb/buffer_putsnoflush.c +++ b/src/libstddjb/buffer_putsnoflush.c @@ -1,9 +1,9 @@ /* ISC license. */ -#include <skalibs/bytestr.h> +#include <string.h> #include <skalibs/buffer.h> -int buffer_putsnoflush (buffer *b, char const *s) +size_t buffer_putsnoflush (buffer *b, char const *s) { - return buffer_putnoflush(b, s, str_len(s)) ; + return buffer_putnoflush(b, s, strlen(s)) ; } diff --git a/src/libstddjb/buffer_putv.c b/src/libstddjb/buffer_putv.c index fc46811..bd902ae 100644 --- a/src/libstddjb/buffer_putv.c +++ b/src/libstddjb/buffer_putv.c @@ -1,10 +1,11 @@ /* ISC license. */ +#include <sys/types.h> +#include <sys/uio.h> #include <skalibs/buffer.h> -#include <skalibs/siovec.h> -int buffer_putv (buffer *b, siovec_t const *v, unsigned int n) +ssize_t buffer_putv (buffer *b, struct iovec const *v, unsigned int n) { - unsigned int w = 0 ; - return buffer_putvall(b, v, n, &w) ? w : -1 ; + size_t w = 0 ; + return buffer_putvall(b, v, n, &w) ? (ssize_t)w : -1 ; } diff --git a/src/libstddjb/buffer_putvall.c b/src/libstddjb/buffer_putvall.c index 22b7ae4..b04ac36 100644 --- a/src/libstddjb/buffer_putvall.c +++ b/src/libstddjb/buffer_putvall.c @@ -1,14 +1,16 @@ /* ISC license. */ +#include <sys/types.h> +#include <sys/uio.h> #include <errno.h> -#include <skalibs/buffer.h> #include <skalibs/siovec.h> +#include <skalibs/buffer.h> -int buffer_putvall (buffer *b, siovec_t const *v, unsigned int n, unsigned int *written) +int buffer_putvall (buffer *b, struct iovec const *v, unsigned int n, size_t *written) { - unsigned int len = siovec_len(v, n) ; - unsigned int w = n ; - siovec_t vv[n] ; + size_t len = siovec_len(v, n) ; + size_t w = n ; + struct iovec vv[n ? n : 1] ; if (*written > len) return (errno = EINVAL, 0) ; while (w--) vv[w] = v[w] ; w = *written ; diff --git a/src/libstddjb/buffer_putvallnf.c b/src/libstddjb/buffer_putvallnf.c index cada660..6f87d13 100644 --- a/src/libstddjb/buffer_putvallnf.c +++ b/src/libstddjb/buffer_putvallnf.c @@ -1,11 +1,14 @@ /* ISC license. */ +#include <sys/types.h> +#include <sys/uio.h> #include <errno.h> +#include <skalibs/siovec.h> #include <skalibs/buffer.h> -int buffer_putvallnoflush (buffer *b, siovec_t const *v, unsigned int n) +int buffer_putvallnoflush (buffer *b, struct iovec const *v, unsigned int n) { - register unsigned int r = buffer_putvnoflush(b, v, n) ; + size_t r = buffer_putvnoflush(b, v, n) ; if (r < siovec_len(v, n)) { buffer_unput(b, r) ; diff --git a/src/libstddjb/buffer_putvflush.c b/src/libstddjb/buffer_putvflush.c index 46f9e03..4bbb329 100644 --- a/src/libstddjb/buffer_putvflush.c +++ b/src/libstddjb/buffer_putvflush.c @@ -1,11 +1,12 @@ /* ISC license. */ +#include <sys/types.h> +#include <sys/uio.h> #include <skalibs/buffer.h> -#include <skalibs/siovec.h> -int buffer_putvflush (buffer *b, siovec_t const *v, unsigned int n) +ssize_t buffer_putvflush (buffer *b, struct iovec const *v, unsigned int n) { - int r = buffer_putv(b, v, n) ; + ssize_t r = buffer_putv(b, v, n) ; if (r < 0) return -1 ; if (!buffer_flush(b)) return -1 ; return r ; diff --git a/src/libstddjb/byte_copy.c b/src/libstddjb/byte_copy.c deleted file mode 100644 index 410fb95..0000000 --- a/src/libstddjb/byte_copy.c +++ /dev/null @@ -1,14 +0,0 @@ -/* ISC license. */ - -#include <skalibs/config.h> - -#ifdef SKALIBS_FLAG_REPLACE_LIBC - -#include <skalibs/bytestr.h> - -void byte_copy (register char *to, register unsigned int n, register char const *from) -{ - while (n--) *to++ = *from++ ; -} - -#endif diff --git a/src/libstddjb/byte_cr.c b/src/libstddjb/byte_cr.c deleted file mode 100644 index d81e7cf..0000000 --- a/src/libstddjb/byte_cr.c +++ /dev/null @@ -1,22 +0,0 @@ -/* ISC license. */ - -#include <skalibs/config.h> - -#ifdef SKALIBS_FLAG_REPLACE_LIBC - -#include <skalibs/bytestr.h> - -void byte_copyr (register char *to, register unsigned int n, register char const *from) -{ - to += n ; - from += n ; - for (;;) - { - if (!n) return; *--to = *--from; --n; - if (!n) return; *--to = *--from; --n; - if (!n) return; *--to = *--from; --n; - if (!n) return; *--to = *--from; --n; - } -} - -#endif diff --git a/src/libstddjb/byte_diff.c b/src/libstddjb/byte_diff.c deleted file mode 100644 index 9e7f107..0000000 --- a/src/libstddjb/byte_diff.c +++ /dev/null @@ -1,22 +0,0 @@ -/* ISC license. */ - -#include <skalibs/config.h> - -#ifdef SKALIBS_FLAG_REPLACE_LIBC - -#include <skalibs/bytestr.h> - -int byte_diff (register char const *s, register unsigned int n, register char const *t) -{ - for (;;) - { - if (!n) return 0; if (*s != *t) break; ++s; ++t; --n; - if (!n) return 0; if (*s != *t) break; ++s; ++t; --n; - if (!n) return 0; if (*s != *t) break; ++s; ++t; --n; - if (!n) return 0; if (*s != *t) break; ++s; ++t; --n; - } - return ((int)(unsigned int)(unsigned char) *s) - - ((int)(unsigned int)(unsigned char) *t) ; -} - -#endif diff --git a/src/libstddjb/byte_in.c b/src/libstddjb/byte_in.c index cb6e5bc..f777991 100644 --- a/src/libstddjb/byte_in.c +++ b/src/libstddjb/byte_in.c @@ -1,14 +1,15 @@ /* ISC license. */ #include <sys/types.h> +#include <string.h> #include <skalibs/bytestr.h> size_t byte_in (char const *s, size_t n, char const *sep, size_t len) { - register char const *t = s ; + char const *t = s ; while (n--) { - if (byte_chr(sep, len, *t) < len) break ; + if (memchr(sep, *t, len)) break ; ++t ; } return t - s ; diff --git a/src/libstddjb/byte_zero.c b/src/libstddjb/byte_zero.c deleted file mode 100644 index 6751210..0000000 --- a/src/libstddjb/byte_zero.c +++ /dev/null @@ -1,15 +0,0 @@ -/* ISC license. */ - -#include <skalibs/config.h> - -#ifdef SKALIBS_FLAG_REPLACE_LIBC - -#include <skalibs/bytestr.h> - -void byte_zero (void *p, register unsigned int n) -{ - register char *s = (char *)p ; - while (n--) *s++ = 0 ; -} - -#endif diff --git a/src/libstddjb/case_diffn.c b/src/libstddjb/case_diffn.c deleted file mode 100644 index 0e75aa5..0000000 --- a/src/libstddjb/case_diffn.c +++ /dev/null @@ -1,23 +0,0 @@ -/* ISC license. */ - -#include <skalibs/config.h> -#include <skalibs/bytestr.h> - -#ifdef SKALIBS_FLAG_REPLACE_LIBC - -int case_diffn (char const *s, char const *t, unsigned int len) -{ - register unsigned char x = 0, y = 0 ; - unsigned char const d = 'a' - 'A' ; - - while (len-- && (x == y)) - { - x = *s++ ; - if (('a' <= x) && (x <= 'z')) x -= d ; - y = *t++ ; - if (('a' <= y) && (y <= 'z')) y -= d ; - } - return (int)(x - y) ; -} - -#endif diff --git a/src/libstddjb/case_diffs.c b/src/libstddjb/case_diffs.c deleted file mode 100644 index 621a8fa..0000000 --- a/src/libstddjb/case_diffs.c +++ /dev/null @@ -1,23 +0,0 @@ -/* ISC license. */ - -#include <skalibs/config.h> -#include <skalibs/bytestr.h> - -#ifdef SKALIBS_FLAG_REPLACE_LIBC - -int case_diffs (char const *s, char const *t) -{ - register unsigned char x = 1, y = 1 ; - unsigned char const d = 'a' - 'A' ; - - while (x && (x == y)) - { - x = *s++ ; - if (('a' <= x) && (x <= 'z')) x -= d ; - y = *t++ ; - if (('a' <= y) && (y <= 'z')) y -= d ; - } - return (int)(x - y) ; -} - -#endif diff --git a/src/libstddjb/cbuffer_get.c b/src/libstddjb/cbuffer_get.c index d322a03..c490c26 100644 --- a/src/libstddjb/cbuffer_get.c +++ b/src/libstddjb/cbuffer_get.c @@ -1,12 +1,14 @@ /* ISC license. */ -#include <skalibs/cbuffer.h> +#include <sys/types.h> +#include <sys/uio.h> #include <skalibs/siovec.h> +#include <skalibs/cbuffer.h> -unsigned int cbuffer_get (cbuffer_t *b, char *s, unsigned int len) +size_t cbuffer_get (cbuffer_t *b, char *s, size_t len) { - siovec_t v[2] ; - register unsigned int w ; + struct iovec v[2] ; + size_t w ; cbuffer_rpeek(b, v) ; w = siovec_gather(v, 2, s, len) ; return cbuffer_RSEEK(b, w) ; diff --git a/src/libstddjb/cbuffer_getv.c b/src/libstddjb/cbuffer_getv.c index 22bd6f7..f27d054 100644 --- a/src/libstddjb/cbuffer_getv.c +++ b/src/libstddjb/cbuffer_getv.c @@ -1,12 +1,14 @@ /* ISC license. */ -#include <skalibs/cbuffer.h> +#include <sys/types.h> +#include <sys/uio.h> #include <skalibs/siovec.h> +#include <skalibs/cbuffer.h> -unsigned int cbuffer_getv (cbuffer_t *b, siovec_t const *v, unsigned int n) +size_t cbuffer_getv (cbuffer_t *b, struct iovec const *v, unsigned int n) { - siovec_t vsrc[2] ; - register unsigned int w ; + struct iovec vsrc[2] ; + size_t w ; cbuffer_rpeek(b, vsrc) ; w = siovec_deal(v, n, vsrc, 2) ; return cbuffer_RSEEK(b, w) ; diff --git a/src/libstddjb/cbuffer_init.c b/src/libstddjb/cbuffer_init.c index eba4765..24ee8b3 100644 --- a/src/libstddjb/cbuffer_init.c +++ b/src/libstddjb/cbuffer_init.c @@ -1,9 +1,10 @@ /* ISC license. */ +#include <sys/types.h> #include <errno.h> #include <skalibs/cbuffer.h> -int cbuffer_init (cbuffer_t *b, char *s, unsigned int len) +int cbuffer_init (cbuffer_t *b, char *s, size_t len) { if (len < 2) return (errno = EINVAL, 0) ; b->x = s ; diff --git a/src/libstddjb/cbuffer_put.c b/src/libstddjb/cbuffer_put.c index 5733d21..2a5fcf8 100644 --- a/src/libstddjb/cbuffer_put.c +++ b/src/libstddjb/cbuffer_put.c @@ -1,12 +1,14 @@ /* ISC license. */ -#include <skalibs/cbuffer.h> +#include <sys/types.h> +#include <sys/uio.h> #include <skalibs/siovec.h> +#include <skalibs/cbuffer.h> -unsigned int cbuffer_put (cbuffer_t *b, char const *s, unsigned int len) +size_t cbuffer_put (cbuffer_t *b, char const *s, size_t len) { - siovec_t v[2] ; - register unsigned int w ; + struct iovec v[2] ; + size_t w ; cbuffer_wpeek(b, v) ; w = siovec_scatter(v, 2, s, len) ; return cbuffer_WSEEK(b, w) ; diff --git a/src/libstddjb/cbuffer_putv.c b/src/libstddjb/cbuffer_putv.c index 6a914de..2fcdee6 100644 --- a/src/libstddjb/cbuffer_putv.c +++ b/src/libstddjb/cbuffer_putv.c @@ -1,12 +1,14 @@ /* ISC license. */ -#include <skalibs/cbuffer.h> +#include <sys/types.h> +#include <sys/uio.h> #include <skalibs/siovec.h> +#include <skalibs/cbuffer.h> -unsigned int cbuffer_putv (cbuffer_t *b, siovec_t const *v, unsigned int n) +size_t cbuffer_putv (cbuffer_t *b, struct iovec const *v, unsigned int n) { - siovec_t vdest[2] ; - register unsigned int w ; + struct iovec vdest[2] ; + size_t w ; cbuffer_wpeek(b, vdest) ; w = siovec_deal(vdest, 2, v, n) ; return cbuffer_WSEEK(b, w) ; diff --git a/src/libstddjb/cbuffer_rpeek.c b/src/libstddjb/cbuffer_rpeek.c index 22a1ef5..58cb207 100644 --- a/src/libstddjb/cbuffer_rpeek.c +++ b/src/libstddjb/cbuffer_rpeek.c @@ -1,21 +1,21 @@ /* ISC license. */ +#include <sys/uio.h> #include <skalibs/cbuffer.h> -#include <skalibs/siovec.h> -void cbuffer_rpeek (cbuffer_t *b, siovec_t *v) +void cbuffer_rpeek (cbuffer_t *b, struct iovec *v) { - v[0].s = b->x + b->p ; + v[0].iov_base = b->x + b->p ; if (b->n >= b->p) { - v[0].len = b->n - b->p ; - v[1].s = 0 ; - v[1].len = 0 ; + v[0].iov_len = b->n - b->p ; + v[1].iov_base = 0 ; + v[1].iov_len = 0 ; } else { - v[0].len = b->a - b->p ; - v[1].s = b->x ; - v[1].len = b->n ; + v[0].iov_len = b->a - b->p ; + v[1].iov_base = b->x ; + v[1].iov_len = b->n ; } } diff --git a/src/libstddjb/cbuffer_rseek.c b/src/libstddjb/cbuffer_rseek.c index 4a98511..98532af 100644 --- a/src/libstddjb/cbuffer_rseek.c +++ b/src/libstddjb/cbuffer_rseek.c @@ -1,10 +1,11 @@ /* ISC license. */ +#include <sys/types.h> #include <skalibs/cbuffer.h> -unsigned int cbuffer_rseek (cbuffer_t *b, unsigned int len) +size_t cbuffer_rseek (cbuffer_t *b, size_t len) { - register unsigned int max = cbuffer_len(b) ; + size_t max = cbuffer_len(b) ; if (len > max) len = max ; return cbuffer_RSEEK(b, len) ; } diff --git a/src/libstddjb/cbuffer_unget.c b/src/libstddjb/cbuffer_unget.c index d1591e6..8ada7fe 100644 --- a/src/libstddjb/cbuffer_unget.c +++ b/src/libstddjb/cbuffer_unget.c @@ -1,10 +1,11 @@ /* ISC license. */ +#include <sys/types.h> #include <skalibs/cbuffer.h> -unsigned int cbuffer_unget (cbuffer_t *b, unsigned int len) +size_t cbuffer_unget (cbuffer_t *b, size_t len) { - register unsigned int max = cbuffer_available(b) ; + size_t max = cbuffer_available(b) ; if (len > max) len = max ; return cbuffer_UNGET(b, len) ; } diff --git a/src/libstddjb/cbuffer_unput.c b/src/libstddjb/cbuffer_unput.c index 8221ca0..40f8f92 100644 --- a/src/libstddjb/cbuffer_unput.c +++ b/src/libstddjb/cbuffer_unput.c @@ -1,10 +1,11 @@ /* ISC license. */ +#include <sys/types.h> #include <skalibs/cbuffer.h> -unsigned int cbuffer_unput (cbuffer_t *b, unsigned int len) +size_t cbuffer_unput (cbuffer_t *b, size_t len) { - register unsigned int max = cbuffer_len(b) ; + size_t max = cbuffer_len(b) ; if (len > max) len = max ; return cbuffer_UNPUT(b, len) ; } diff --git a/src/libstddjb/cbuffer_wpeek.c b/src/libstddjb/cbuffer_wpeek.c index a2c6a63..a1e502e 100644 --- a/src/libstddjb/cbuffer_wpeek.c +++ b/src/libstddjb/cbuffer_wpeek.c @@ -1,22 +1,23 @@ /* ISC license. */ +#include <sys/types.h> +#include <sys/uio.h> #include <skalibs/cbuffer.h> -#include <skalibs/siovec.h> -void cbuffer_wpeek (cbuffer_t *b, siovec_t *v) +void cbuffer_wpeek (cbuffer_t *b, struct iovec *v) { - unsigned int last = (b->a - 1 + b->p) % b->a ; - v[0].s = b->x + b->n ; + size_t last = (b->a - 1 + b->p) % b->a ; + v[0].iov_base = b->x + b->n ; if (last >= b->n) { - v[0].len = last - b->n ; - v[1].s = 0 ; - v[1].len = 0 ; + v[0].iov_len = last - b->n ; + v[1].iov_base = 0 ; + v[1].iov_len = 0 ; } else { - v[0].len = b->a - b->n ; - v[1].s = b->x ; - v[1].len = last ; + v[0].iov_len = b->a - b->n ; + v[1].iov_base = b->x ; + v[1].iov_len = last ; } } diff --git a/src/libstddjb/cbuffer_wseek.c b/src/libstddjb/cbuffer_wseek.c index 6b90ab6..3d44d44 100644 --- a/src/libstddjb/cbuffer_wseek.c +++ b/src/libstddjb/cbuffer_wseek.c @@ -1,10 +1,11 @@ /* ISC license. */ +#include <sys/types.h> #include <skalibs/cbuffer.h> -unsigned int cbuffer_wseek (cbuffer_t *b, unsigned int len) +size_t cbuffer_wseek (cbuffer_t *b, size_t len) { - register unsigned int max = cbuffer_available(b) ; + size_t max = cbuffer_available(b) ; if (len > max) len = max ; return cbuffer_WSEEK(b, len) ; } diff --git a/src/libstddjb/child_spawn.c b/src/libstddjb/child_spawn.c index 78b45ac..db00bd3 100644 --- a/src/libstddjb/child_spawn.c +++ b/src/libstddjb/child_spawn.c @@ -49,10 +49,10 @@ pid_t child_spawn (char const *prog, char const *const *argv, char const *const int p[n ? n : 1][2] ; pid_t pid ; int e ; - unsigned int m = sizeof(NOFDVAR) ; + size_t m = sizeof(NOFDVAR) ; unsigned int i = 0 ; char modifs[m + 1 + n * UINT_FMT] ; - byte_copy(modifs, sizeof(NOFDVAR), NOFDVAR "=") ; + memcpy(modifs, NOFDVAR "=", sizeof(NOFDVAR)) ; for (; i < n ; i++) if (pipe(p[i]) < 0) { e = errno ; goto errpi ; } for (i = 0 ; i < n ; i++) if ((ndelay_on(p[i][i & 1]) < 0) || (coe(p[i][i & 1]) < 0)) @@ -96,7 +96,7 @@ pid_t child_spawn (char const *prog, char const *const *argv, char const *const } { int haspath = !!env_get("PATH") ; - unsigned int envlen = env_len(envp) ; + size_t envlen = env_len(envp) ; char const *newenv[envlen + 2] ; if (!env_merge(newenv, envlen+2, envp, envlen, modifs, m)) goto errsp ; if (!haspath && (setenv("PATH", SKALIBS_DEFAULTPATH, 0) < 0)) @@ -119,10 +119,10 @@ pid_t child_spawn (char const *prog, char const *const *argv, char const *const if (pid < 0) { e = errno ; goto errsp ; } else if (!pid) { - unsigned int len = str_len(PROG) ; + size_t len = strlen(PROG) ; char name[len + 9] ; - byte_copy(name, len, PROG) ; - byte_copy(name + len, 9, " (child)") ; + memcpy(name, PROG, len) ; + memcpy(name + len, " (child)", 9) ; PROG = name ; fd_close(syncpipe[0]) ; if (n >= 2) diff --git a/src/libstddjb/child_spawn0.c b/src/libstddjb/child_spawn0.c index d1eddba..8c114b8 100644 --- a/src/libstddjb/child_spawn0.c +++ b/src/libstddjb/child_spawn0.c @@ -45,7 +45,9 @@ pid_t child_spawn0 (char const *prog, char const *const *argv, char const *const #else #include <unistd.h> +#include <string.h> #include <skalibs/allreadwrite.h> +#include <skalibs/strerr2.h> #include <skalibs/sig.h> #include <skalibs/djbunix.h> @@ -66,6 +68,11 @@ pid_t child_spawn0 (char const *prog, char const *const *argv, char const *const } if (!pid) { + size_t len = strlen(PROG) ; + char name[len + 9] ; + memcpy(name, PROG, len) ; + memcpy(name + len, " (child)", 9) ; + PROG = name ; fd_close(p[0]) ; sig_blocknone() ; pathexec_run(prog, argv, envp) ; diff --git a/src/libstddjb/child_spawn1_internal.c b/src/libstddjb/child_spawn1_internal.c index f833a15..8bd1678 100644 --- a/src/libstddjb/child_spawn1_internal.c +++ b/src/libstddjb/child_spawn1_internal.c @@ -66,7 +66,9 @@ pid_t child_spawn1_internal (char const *prog, char const *const *argv, char con #else +#include <string.h> #include <skalibs/allreadwrite.h> +#include <skalibs/strerr2.h> #include <skalibs/sig.h> pid_t child_spawn1_internal (char const *prog, char const *const *argv, char const *const *envp, int *p, int to) @@ -95,6 +97,11 @@ pid_t child_spawn1_internal (char const *prog, char const *const *argv, char con } if (!pid) { + size_t len = strlen(PROG) ; + char name[len + 9] ; + memcpy(name, PROG, len) ; + memcpy(name + len, " (child)", 9) ; + PROG = name ; fd_close(syncp[0]) ; fd_close(p[!(to & 1)]) ; if (fd_move(to & 1, p[to & 1]) < 0) goto err ; diff --git a/src/libstddjb/child_spawn2.c b/src/libstddjb/child_spawn2.c index 701be26..d17ff7b 100644 --- a/src/libstddjb/child_spawn2.c +++ b/src/libstddjb/child_spawn2.c @@ -21,7 +21,7 @@ #else -#include <skalibs/bytestr.h> +#include <string.h> #include <skalibs/allreadwrite.h> #include <skalibs/sig.h> #include <skalibs/strerr2.h> @@ -87,10 +87,10 @@ pid_t child_spawn2 (char const *prog, char const *const *argv, char const *const if (pid < 0) { e = errno ; goto errsp ; } else if (!pid) { - unsigned int len = str_len(PROG) ; + size_t len = strlen(PROG) ; char name[len + 9] ; - byte_copy(name, len, PROG) ; - byte_copy(name + len, 9, " (child)") ; + memcpy(name, PROG, len) ; + memcpy(name + len, " (child)", 9) ; PROG = name ; fd_close(syncpipe[0]) ; if (fd_move2(fds[0], p[1][0], fds[1], p[0][1]) < 0) goto syncdie ; diff --git a/src/libstddjb/coe.c b/src/libstddjb/coe.c index a12f9cb..9f9f184 100644 --- a/src/libstddjb/coe.c +++ b/src/libstddjb/coe.c @@ -5,7 +5,7 @@ int coe (int fd) { - register int flags = fcntl(fd, F_GETFD, 0) ; - if (flags < 0) return -1 ; - return fcntl(fd, F_SETFD, flags | FD_CLOEXEC) ; + int flags = fcntl(fd, F_GETFD, 0) ; + if (flags < 0) return -1 ; + return fcntl(fd, F_SETFD, flags | FD_CLOEXEC) ; } diff --git a/src/libstddjb/dirname.c b/src/libstddjb/dirname.c deleted file mode 100644 index 1def443..0000000 --- a/src/libstddjb/dirname.c +++ /dev/null @@ -1,19 +0,0 @@ -/* ISC license. */ - -/* MT-unsafe */ - -#include <skalibs/bytestr.h> -#include <skalibs/stralloc.h> -#include <skalibs/djbunix.h> - -char *dirname (char *s) -{ - static stralloc dirname_sa = STRALLOC_ZERO ; - static char dot0[2] = "." ; - char *dot = dot0 ; - if (!s) return dot ; - dirname_sa.len = 0 ; - if (!sadirname(&dirname_sa, s, str_len(s))) return 0 ; - if (!stralloc_0(&dirname_sa)) return 0 ; - return dirname_sa.s ; -} diff --git a/src/libstddjb/doublefork.c b/src/libstddjb/doublefork.c index 5a1f7b1..5d4e0e9 100644 --- a/src/libstddjb/doublefork.c +++ b/src/libstddjb/doublefork.c @@ -19,7 +19,7 @@ pid_t doublefork () { case -1: { - register int e = errno ; + int e = errno ; fd_close(fd[1]) ; fd_close(fd[0]) ; errno = e ; @@ -35,13 +35,13 @@ pid_t doublefork () case -1: _exit(errno) ; case 0: fd_close(fd[1]) ; return 0 ; } - uint64_pack_big(pack, (uint64)pid) ; + uint64_pack_big(pack, pid) ; _exit((allwrite(fd[1], pack, 8) < 8) ? errno : 0) ; } } fd_close(fd[1]) ; { - uint64 grandchild = 0 ; + uint64_t grandchild = 0 ; int wstat ; if (allread(fd[0], pack, 8) < 8) grandchild = 1 ; fd_close(fd[0]) ; diff --git a/src/libstddjb/envdir.c b/src/libstddjb/envdir.c index 7866c7a..6992654 100644 --- a/src/libstddjb/envdir.c +++ b/src/libstddjb/envdir.c @@ -1,6 +1,7 @@ /* ISC license. */ #include <unistd.h> +#include <string.h> #include <errno.h> #include <skalibs/bytestr.h> #include <skalibs/env.h> @@ -14,8 +15,8 @@ int envdir_internal (char const *path, stralloc *modifs, unsigned int options, c { char buf[MAXVARSIZE + 1] ; unsigned int n = 0 ; - unsigned int pathlen = str_len(path) ; - unsigned int modifbase = modifs->len ; + size_t pathlen = strlen(path) ; + size_t modifbase = modifs->len ; int wasnull = !modifs->s ; DIR *dir ; if (!nullis) return (errno = EINVAL, -1) ; @@ -24,19 +25,19 @@ int envdir_internal (char const *path, stralloc *modifs, unsigned int options, c for (;;) { direntry *d ; - unsigned int len ; - register int r ; + size_t len ; + ssize_t r ; errno = 0 ; d = readdir(dir) ; if (!d) break ; if (d->d_name[0] == '.') continue ; - len = str_len(d->d_name) ; + len = strlen(d->d_name) ; if (str_chr(d->d_name, '=') < len) continue ; { char tmp[pathlen + len + 2] ; - byte_copy(tmp, pathlen, path) ; + memcpy(tmp, path, pathlen) ; tmp[pathlen] = '/' ; - byte_copy(tmp + pathlen + 1, len + 1, d->d_name) ; + memcpy(tmp + pathlen + 1, d->d_name, len + 1) ; r = openreadnclose(tmp, buf, MAXVARSIZE) ; } if (r < 0) @@ -60,8 +61,8 @@ int envdir_internal (char const *path, stralloc *modifs, unsigned int options, c } } { - register unsigned int i = 0 ; - for (; i < (unsigned int)r ; i++) if (!buf[i]) buf[i] = nullis ; + size_t i = 0 ; + for (; i < (size_t)r ; i++) if (!buf[i]) buf[i] = nullis ; } buf[r++] = 0 ; if (!env_addmodif(modifs, d->d_name, buf)) goto err ; @@ -75,7 +76,7 @@ int envdir_internal (char const *path, stralloc *modifs, unsigned int options, c err: { - register int e = errno ; + int e = errno ; dir_close(dir) ; if (wasnull) stralloc_free(modifs) ; else modifs->len = modifbase ; errno = e ; diff --git a/src/libstddjb/error_str.c b/src/libstddjb/error_str.c deleted file mode 100644 index 6aca43f..0000000 --- a/src/libstddjb/error_str.c +++ /dev/null @@ -1,277 +0,0 @@ -/* ISC license. */ - -#include <skalibs/config.h> -#include <skalibs/error.h> - -#ifndef SKALIBS_FLAG_REPLACE_LIBC - -#include <string.h> - -char const *error_str (register int i) -{ - return (char const *)strerror(i) ; -} - -#else - -#include <errno.h> - -#define X(e, s) case e : return s ; -#define Y(e, s) if (i == e) return s ; - -char const *error_str (register int i) -{ - Y(EWOULDBLOCK, "input/output would block") - Y(EAGAIN, "temporary failure") - Y(EINVAL, "invalid argument") - - switch (i) - { - X(0, "no error") - X(EINTR, "interrupted system call") - X(ENOMEM, "out of memory") - X(ENOENT, "file does not exist") - X(ETXTBSY, "text busy") - X(EIO, "input/output error") - X(EEXIST, "file already exists") - X(ETIMEDOUT, "timed out") - X(EINPROGRESS, "operation in progress") - X(EPIPE, "broken pipe") - X(EPERM, "permission denied") - X(EACCES, "access denied") - X(ENODEV, "device not configured") - X(EPROTO, "protocol error") - X(EISDIR, "is a directory") - X(ECONNREFUSED, "connection refused") - X(ENOTDIR, "not a directory") - X(ENOTSOCK, "not a socket") - X(EDOM, "input out of range") - X(ENOBUFS, "out of buffer space") - -#ifdef ESRCH - X(ESRCH, "no such process") -#endif -#ifdef E2BIG - X(E2BIG, "argument list too long") -#endif -#ifdef ENOEXEC - X(ENOEXEC, "exec format error") -#endif -#ifdef EBADF - X(EBADF, "file descriptor not open") -#endif -#ifdef ECHILD - X(ECHILD, "no child processes") -#endif -#ifdef EDEADLK - X(EDEADLK, "operation would cause deadlock") -#endif -#ifdef EFAULT - X(EFAULT, "bad address") -#endif -#ifdef ENOTBLK - X(ENOTBLK, "not a block device") -#endif -#ifdef EBUSY - X(EBUSY, "device busy") -#endif -#ifdef EXDEV - X(EXDEV, "cross-device link") -#endif -#ifdef ENFILE - X(ENFILE, "system cannot open more files") -#endif -#ifdef EMFILE - X(EMFILE, "process cannot open more files") -#endif -#ifdef ENOTTY - X(ENOTTY, "not a tty") -#endif -#ifdef EFBIG - X(EFBIG, "file too big") -#endif -#ifdef ENOSPC - X(ENOSPC, "out of disk space") -#endif -#ifdef ESPIPE - X(ESPIPE, "unseekable descriptor") -#endif -#ifdef EROFS - X(EROFS, "read-only file system") -#endif -#ifdef EMLINK - X(EMLINK, "too many links") -#endif -#ifdef ERANGE - X(ERANGE, "output out of range") -#endif -#ifdef EALREADY - X(EALREADY, "operation already in progress") -#endif -#ifdef EDESTADDRREQ - X(EDESTADDRREQ, "destination address required") -#endif -#ifdef EMSGSIZE - X(EMSGSIZE, "message too long") -#endif -#ifdef EPROTOTYPE - X(EPROTOTYPE, "incorrect protocol type") -#endif -#ifdef ENOPROTOOPT - X(ENOPROTOOPT, "protocol not available") -#endif -#ifdef EPROTONOSUPPORT - X(EPROTONOSUPPORT, "protocol not supported") -#endif -#ifdef ESOCKTNOSUPPORT - X(ESOCKTNOSUPPORT, "socket type not supported") -#endif -#ifdef EOPNOTSUPP - X(EOPNOTSUPP, "operation not supported") -#endif -#ifdef EPFNOSUPPORT - X(EPFNOSUPPORT, "protocol family not supported") -#endif -#ifdef EAFNOSUPPORT - X(EAFNOSUPPORT, "address family not supported") -#endif -#ifdef EADDRINUSE - X(EADDRINUSE, "address already used") -#endif -#ifdef EADDRNOTAVAIL - X(EADDRNOTAVAIL, "address not available") -#endif -#ifdef ENETDOWN - X(ENETDOWN, "network down") -#endif -#ifdef ENETUNREACH - X(ENETUNREACH, "network unreachable") -#endif -#ifdef ENETRESET - X(ENETRESET, "network reset") -#endif -#ifdef ECONNABORTED - X(ECONNABORTED, "connection aborted") -#endif -#ifdef ECONNRESET - X(ECONNRESET, "connection reset") -#endif -#ifdef EISCONN - X(EISCONN, "already connected") -#endif -#ifdef ENOTCONN - X(ENOTCONN, "not connected") -#endif -#ifdef ESHUTDOWN - X(ESHUTDOWN, "socket shut down") -#endif -#ifdef ETOOMANYREFS - X(ETOOMANYREFS, "too many references") -#endif -#ifdef ELOOP - X(ELOOP, "symbolic link loop") -#endif -#ifdef ENAMETOOLONG - X(ENAMETOOLONG, "file name too long") -#endif -#ifdef EHOSTDOWN - X(EHOSTDOWN, "host down") -#endif -#ifdef EHOSTUNREACH - X(EHOSTUNREACH, "host unreachable") -#endif -#ifdef ENOTEMPTY - X(ENOTEMPTY, "directory not empty") -#endif -#ifdef EPROCLIM - X(EPROCLIM, "too many processes") -#endif -#ifdef EUSERS - X(EUSERS, "too many users") -#endif -#ifdef EDQUOT - X(EDQUOT, "disk quota exceeded") -#endif -#ifdef ESTALE - X(ESTALE, "stale NFS file handle") -#endif -#ifdef EREMOTE - X(EREMOTE, "too many levels of remote in path") -#endif -#ifdef EBADRPC - X(EBADRPC, "RPC structure is bad") -#endif -#ifdef ERPCMISMATCH - X(ERPCMISMATCH, "RPC version mismatch") -#endif -#ifdef EPROGUNAVAIL - X(EPROGUNAVAIL, "RPC program unavailable") -#endif -#ifdef EPROGMISMATCH - X(EPROGMISMATCH, "program version mismatch") -#endif -#ifdef EPROCUNAVAIL - X(EPROCUNAVAIL, "bad procedure for program") -#endif -#ifdef ENOLCK - X(ENOLCK, "no locks available") -#endif -#ifdef ENOSYS - X(ENOSYS, "system call not available") -#endif -#ifdef EFTYPE - X(EFTYPE, "bad file type") -#endif -#ifdef EAUTH - X(EAUTH, "authentication error") -#endif -#ifdef ENEEDAUTH - X(ENEEDAUTH, "not authenticated") -#endif -#ifdef ENOSTR - X(ENOSTR, "not a stream device") -#endif -#ifdef ETIME - X(ETIME, "timer expired") -#endif -#ifdef ENOSR - X(ENOSR, "out of stream resources") -#endif -#ifdef ENOMSG - X(ENOMSG, "no message of desired type") -#endif -#ifdef EBADMSG - X(EBADMSG, "bad message type") -#endif -#ifdef EIDRM - X(EIDRM, "identifier removed") -#endif -#ifdef ENONET - X(ENONET, "machine not on network") -#endif -#ifdef ERREMOTE - X(ERREMOTE, "object not local") -#endif -#ifdef ENOLINK - X(ENOLINK, "link severed") -#endif -#ifdef EADV - X(EADV, "advertise error") -#endif -#ifdef ESRMNT - X(ESRMNT, "srmount error") -#endif -#ifdef ECOMM - X(ECOMM, "communication error") -#endif -#ifdef EMULTIHOP - X(EMULTIHOP, "multihop attempted") -#endif -#ifdef EREMCHG - X(EREMCHG, "remote address changed") -#endif - default : return "unknown error" ; - } -} - -#endif diff --git a/src/libstddjb/execvep.c b/src/libstddjb/execvep.c index 1639236..3dae8bc 100644 --- a/src/libstddjb/execvep.c +++ b/src/libstddjb/execvep.c @@ -1,6 +1,7 @@ /* ISC license. */ #include <unistd.h> +#include <string.h> #include <errno.h> #include <skalibs/bytestr.h> #include <skalibs/djbunix.h> @@ -12,18 +13,18 @@ void execvep (char const *file, char const *const *argv, char const *const *envp execve(file, (char *const *)argv, (char *const *)envp) ; /* execve prototype sucks */ else { - unsigned int pathlen = str_len(path) + 1 ; - unsigned int filelen = str_len(file) ; + size_t pathlen = strlen(path) + 1 ; + size_t filelen = strlen(file) ; int savederrno = 0 ; while (pathlen) { - unsigned int split = byte_chr(path, pathlen - 1, ':') ; + size_t split = byte_chr(path, pathlen - 1, ':') ; if (split) { char tmp[split + 2 + filelen] ; - byte_copy(tmp, split, path) ; + memcpy(tmp, path, split) ; tmp[split] = '/' ; - byte_copy(tmp + split + 1, filelen + 1, file) ; + memcpy(tmp + split + 1, file, filelen + 1) ; execve(tmp, (char *const *)argv, (char *const *)envp) ; if (errno != ENOENT) { diff --git a/src/libstddjb/fd_read.c b/src/libstddjb/fd_read.c index 9664024..43453b8 100644 --- a/src/libstddjb/fd_read.c +++ b/src/libstddjb/fd_read.c @@ -1,13 +1,12 @@ /* ISC license. */ -#include <sys/types.h> #include <unistd.h> #include <errno.h> #include <skalibs/allreadwrite.h> ssize_t fd_read (int fd, char *buf, size_t len) { - register ssize_t r ; + ssize_t r ; do r = read(fd, buf, len) ; while ((r == -1) && (errno == EINTR)) ; return r ; diff --git a/src/libstddjb/fd_write.c b/src/libstddjb/fd_write.c index c6758fb..a93c2d9 100644 --- a/src/libstddjb/fd_write.c +++ b/src/libstddjb/fd_write.c @@ -1,13 +1,12 @@ /* ISC license. */ -#include <sys/types.h> #include <unistd.h> #include <errno.h> #include <skalibs/allreadwrite.h> ssize_t fd_write (int fd, char const *buf, size_t len) { - register ssize_t r ; + ssize_t r ; do r = write(fd, buf, len) ; while ((r == -1) && (errno == EINTR)) ; return r ; diff --git a/src/libstddjb/filecopy_suffix.c b/src/libstddjb/filecopy_suffix.c index 70673ea..3cc5218 100644 --- a/src/libstddjb/filecopy_suffix.c +++ b/src/libstddjb/filecopy_suffix.c @@ -1,22 +1,22 @@ /* ISC license. */ +#include <string.h> #include <errno.h> #include <unistd.h> #include <stdio.h> -#include <skalibs/bytestr.h> #include <skalibs/djbunix.h> int filecopy_suffix (char const *src, char const *dst, unsigned int mode, char const *suffix) { - unsigned int dstlen = str_len(dst) ; - unsigned int suffixlen = str_len(suffix) ; + size_t dstlen = strlen(dst) ; + size_t suffixlen = strlen(suffix) ; char tmp[dstlen + suffixlen + 1] ; - byte_copy(tmp, dstlen, dst) ; - byte_copy(tmp + dstlen, suffixlen + 1, suffix) ; + memcpy(tmp, dst, dstlen) ; + memcpy(tmp + dstlen, suffix, suffixlen + 1) ; if (!filecopy_unsafe(src, tmp, mode)) return 0 ; if (rename(tmp, dst) < 0) { - register int e = errno ; + int e = errno ; unlink(tmp) ; errno = e ; return 0 ; diff --git a/src/libstddjb/filecopy_unsafe.c b/src/libstddjb/filecopy_unsafe.c index b60c783..68bcc5b 100644 --- a/src/libstddjb/filecopy_unsafe.c +++ b/src/libstddjb/filecopy_unsafe.c @@ -12,14 +12,14 @@ int filecopy_unsafe (char const *src, char const *dst, unsigned int mode) d = open3(dst, O_WRONLY | O_CREAT | O_TRUNC, mode) ; if (d < 0) { - register int e = errno ; + int e = errno ; fd_close(s) ; errno = e ; return 0 ; } if (fd_cat(s, d) < 0) { - register int e = errno ; + int e = errno ; fd_close(d) ; fd_close(s) ; errno = e ; diff --git a/src/libstddjb/getlnmax.c b/src/libstddjb/getlnmax.c index e3fde8f..6f6783a 100644 --- a/src/libstddjb/getlnmax.c +++ b/src/libstddjb/getlnmax.c @@ -1,19 +1,21 @@ /* ISC license. */ +#include <sys/types.h> +#include <sys/uio.h> #include <errno.h> #include <skalibs/bytestr.h> #include <skalibs/buffer.h> #include <skalibs/skamisc.h> -int getlnmax (buffer *b, char *d, unsigned int max, unsigned int *w, char sep) +int getlnmax (buffer *b, char *d, size_t max, size_t *w, char sep) { if (max < *w) return (errno = EINVAL, -1) ; for (;;) { - siovec_t v[2] ; - unsigned int len = buffer_len(b) ; - unsigned int pos ; - int r ; + struct iovec v[2] ; + size_t len = buffer_len(b) ; + size_t pos ; + ssize_t r ; buffer_rpeek(b, v) ; if (len > max - *w) len = max - *w ; pos = siovec_bytechr(v, 2, sep) ; diff --git a/src/libstddjb/getlnmaxsep.c b/src/libstddjb/getlnmaxsep.c index 2bde443..8505417 100644 --- a/src/libstddjb/getlnmaxsep.c +++ b/src/libstddjb/getlnmaxsep.c @@ -1,19 +1,21 @@ /* ISC license. */ +#include <sys/types.h> +#include <sys/uio.h> #include <errno.h> -#include <skalibs/bytestr.h> #include <skalibs/buffer.h> +#include <skalibs/siovec.h> #include <skalibs/skamisc.h> -int getlnmaxsep (buffer *b, char *d, unsigned int max, unsigned int *w, char const *sep, unsigned int seplen) +int getlnmaxsep (buffer *b, char *d, size_t max, size_t *w, char const *sep, size_t seplen) { if (max < *w) return (errno = EINVAL, -1) ; for (;;) { - siovec_t v[2] ; - unsigned int len = buffer_len(b) ; - unsigned int pos ; - int r ; + struct iovec v[2] ; + size_t len = buffer_len(b) ; + size_t pos ; + ssize_t r ; buffer_rpeek(b, v) ; if (len > max - *w) len = max - *w ; pos = siovec_bytein(v, 2, sep, seplen) ; diff --git a/src/libstddjb/hiercopy_tmp.c b/src/libstddjb/hiercopy_tmp.c index bcff2b2..ef76b57 100644 --- a/src/libstddjb/hiercopy_tmp.c +++ b/src/libstddjb/hiercopy_tmp.c @@ -2,10 +2,10 @@ #include <sys/types.h> #include <sys/stat.h> +#include <string.h> #include <unistd.h> #include <errno.h> #include <fcntl.h> -#include <skalibs/bytestr.h> #include <skalibs/strerr2.h> #include <skalibs/stralloc.h> #include <skalibs/direntry.h> @@ -13,22 +13,22 @@ static int dircopy (char const *src, char const *dst, mode_t mode, stralloc *tmp) { - unsigned int tmpbase = tmp->len ; - unsigned int maxlen = 0 ; + size_t tmpbase = tmp->len ; + size_t maxlen = 0 ; { DIR *dir = opendir(src) ; if (!dir) return 0 ; for (;;) { direntry *d ; - register unsigned int n ; + size_t n ; errno = 0 ; d = readdir(dir) ; if (!d) break ; if (d->d_name[0] == '.') if (((d->d_name[1] == '.') && !d->d_name[2]) || !d->d_name[1]) continue ; - n = str_len(d->d_name) ; + n = strlen(d->d_name) ; if (n > maxlen) maxlen = n ; if (!stralloc_catb(tmp, d->d_name, n+1)) break ; } @@ -50,20 +50,20 @@ static int dircopy (char const *src, char const *dst, mode_t mode, stralloc *tmp if (!S_ISDIR(st.st_mode)) { errno = ENOTDIR ; goto err ; } } { - unsigned int srclen = str_len(src) ; - unsigned int dstlen = str_len(dst) ; - unsigned int i = tmpbase ; + size_t srclen = strlen(src) ; + size_t dstlen = strlen(dst) ; + size_t i = tmpbase ; char srcbuf[srclen + maxlen + 2] ; char dstbuf[dstlen + maxlen + 2] ; - byte_copy(srcbuf, srclen, src) ; - byte_copy(dstbuf, dstlen, dst) ; + memcpy(srcbuf, src, srclen) ; + memcpy(dstbuf, dst, dstlen) ; srcbuf[srclen] = '/' ; dstbuf[dstlen] = '/' ; while (i < tmp->len) { - register unsigned int n = str_len(tmp->s + i) + 1 ; - byte_copy(srcbuf + srclen + 1, n, tmp->s + i) ; - byte_copy(dstbuf + dstlen + 1, n, tmp->s + i) ; + size_t n = strlen(tmp->s + i) + 1 ; + memcpy(srcbuf + srclen + 1, tmp->s + i, n) ; + memcpy(dstbuf + dstlen + 1, tmp->s + i, n) ; i += n ; hiercopy_tmp(srcbuf, dstbuf, tmp) ; } @@ -94,14 +94,9 @@ int hiercopy_tmp (char const *src, char const *dst, stralloc *tmp) } else if (S_ISLNK(st.st_mode)) { - unsigned int tmpbase = tmp->len ; + size_t tmpbase = tmp->len ; if (sareadlink(tmp, src) < 0) return 0 ; - if (!stralloc_0(tmp)) - { - tmp->len = tmpbase ; - return 0 ; - } - if (symlink(tmp->s + tmpbase, dst) < 0) + if (!stralloc_0(tmp) || symlink(tmp->s + tmpbase, dst) < 0) { tmp->len = tmpbase ; return 0 ; diff --git a/src/libstddjb/iobuffer_kfromu.c b/src/libstddjb/iobuffer_kfromu.c index 7f2feda..7942541 100644 --- a/src/libstddjb/iobuffer_kfromu.c +++ b/src/libstddjb/iobuffer_kfromu.c @@ -13,15 +13,13 @@ int iobuffer_kfromu (iobufferk *k, iobufferu *u) { - struct iovec iov[2] ; - siovec_t v[2] ; - int r ; + struct iovec v[2] ; + ssize_t r ; buffer_rpeek(&u->b[0], v) ; - iovec_from_siovec(iov, v, 2) ; - r = vmsplice(k->p[1], iov, 2, 0) ; + r = vmsplice(k->p[1], v, 2, 0) ; if (r < 0) return 0 ; k->n += r ; - buffer_rseek(&u->b[0], (unsigned int)r) ; + buffer_rseek(&u->b[0], r) ; u->b[1].c.p = u->b[0].c.p ; return iobufferu_isempty(u) ; } diff --git a/src/libstddjb/iovec_from_siovec.c b/src/libstddjb/iovec_from_siovec.c deleted file mode 100644 index 154cca5..0000000 --- a/src/libstddjb/iovec_from_siovec.c +++ /dev/null @@ -1,14 +0,0 @@ -/* ISC license. */ - -#include <sys/types.h> -#include <sys/uio.h> -#include <skalibs/siovec.h> - -void iovec_from_siovec (struct iovec *iov, siovec_t const *v, unsigned int n) -{ - while (n--) - { - iov[n].iov_base = v[n].s ; - iov[n].iov_len = v[n].len ; - } -} diff --git a/src/libstddjb/ip6_fmt.c b/src/libstddjb/ip6_fmt.c index eb6acc0..8d56a90 100644 --- a/src/libstddjb/ip6_fmt.c +++ b/src/libstddjb/ip6_fmt.c @@ -8,7 +8,7 @@ static inline size_t xfmt16 (char *s, char const *key) { - register size_t j = 0 ; + size_t j = 0 ; j += px((unsigned char)key[0] >> 4) ; j += px((unsigned char)key[0] & 15) ; j += px((unsigned char)key[1] >> 4) ; @@ -21,8 +21,8 @@ static inline unsigned int find_colcol (char const *key, unsigned int *pos) diuint z[4] = { DIUINT_ZERO, DIUINT_ZERO, DIUINT_ZERO, DIUINT_ZERO } ; unsigned int j = 0 ; unsigned int max = 0 ; - register int iszero = 0 ; - register unsigned int i = 0 ; + int iszero = 0 ; + unsigned int i = 0 ; for ( ; i < 8 ; i++) { if (key[i<<1] || key[(i<<1)+1]) @@ -59,9 +59,9 @@ static inline unsigned int find_colcol (char const *key, unsigned int *pos) size_t ip6_fmt (char *s, char const *ip6) { size_t w = 0 ; - register unsigned int i = 0 ; unsigned int pos = 8 ; unsigned int len = find_colcol(ip6, &pos) ; + unsigned int i = 0 ; for (; i < 8 ; i++) { if (i == pos) diff --git a/src/libstddjb/lock_ex.c b/src/libstddjb/lock_ex.c index fde901b..19b9a9c 100644 --- a/src/libstddjb/lock_ex.c +++ b/src/libstddjb/lock_ex.c @@ -11,7 +11,7 @@ int lock_ex (int fd) { - register int r ; + int r ; do r = flock(fd, LOCK_EX) ; while ((r == -1) && (errno == EINTR)) ; @@ -27,7 +27,7 @@ int lock_ex (int fd) int lock_ex (int fd) { - register int r ; + int r ; do r = lockf(fd, F_LOCK, 0) ; while ((r == -1) && (errno == EINTR)) ; diff --git a/src/libstddjb/lock_exnb.c b/src/libstddjb/lock_exnb.c index 7fed9f0..a1785a9 100644 --- a/src/libstddjb/lock_exnb.c +++ b/src/libstddjb/lock_exnb.c @@ -11,7 +11,7 @@ int lock_exnb (int fd) { - register int r ; + int r ; do r = flock(fd, LOCK_EX | LOCK_NB) ; while ((r == -1) && (errno == EINTR)) ; @@ -27,7 +27,7 @@ int lock_exnb (int fd) int lock_exnb (int fd) { - register int r ; + int r ; do r = lockf(fd, F_TLOCK, 0) ; while ((r == -1) && (errno == EINTR)) ; diff --git a/src/libstddjb/ndelay_off.c b/src/libstddjb/ndelay_off.c index 828acfa..209fd2b 100644 --- a/src/libstddjb/ndelay_off.c +++ b/src/libstddjb/ndelay_off.c @@ -1,11 +1,10 @@ /* ISC license. */ -#include <sys/types.h> #include <fcntl.h> #include <skalibs/djbunix.h> int ndelay_off (int fd) { - register int got = fcntl(fd, F_GETFL) ; + int got = fcntl(fd, F_GETFL) ; return (got == -1) ? -1 : fcntl(fd, F_SETFL, got & ~O_NONBLOCK) ; } diff --git a/src/libstddjb/ndelay_on.c b/src/libstddjb/ndelay_on.c index 186590b..63ffa58 100644 --- a/src/libstddjb/ndelay_on.c +++ b/src/libstddjb/ndelay_on.c @@ -1,11 +1,10 @@ /* ISC license. */ -#include <sys/types.h> #include <fcntl.h> #include <skalibs/djbunix.h> int ndelay_on (int fd) { - register int got = fcntl(fd, F_GETFL) ; + int got = fcntl(fd, F_GETFL) ; return (got == -1) ? -1 : fcntl(fd, F_SETFL, got | O_NONBLOCK) ; } diff --git a/src/libstddjb/netstring_get.c b/src/libstddjb/netstring_get.c index c2f8b05..dee6821 100644 --- a/src/libstddjb/netstring_get.c +++ b/src/libstddjb/netstring_get.c @@ -2,7 +2,7 @@ #include <sys/types.h> #include <errno.h> -#include <skalibs/uint64.h> +#include <skalibs/types.h> #include <skalibs/allreadwrite.h> #include <skalibs/bytestr.h> #include <skalibs/buffer.h> @@ -16,20 +16,20 @@ int netstring_okeof (buffer *b, size_t w) return (errno == EPIPE) && !w && buffer_isempty(b) ? (errno = 0, 1) : 0 ; } -ssize_t netstring_get (buffer *b, stralloc *sa, size_t *state) +int netstring_get (buffer *b, stralloc *sa, size_t *state) { if (!*state) { size_t n ; size_t len ; - char buf[UINT64_FMT] ; - if (b->c.a < UINT64_FMT+1) return (errno = EINVAL, -1) ; + char buf[SIZE_FMT] ; + if (b->c.a < SIZE_FMT+1) return (errno = EINVAL, -1) ; for (;;) { - register int r ; - len = buffer_getnofill(b, buf, UINT64_FMT) ; + ssize_t r ; + len = buffer_getnofill(b, buf, SIZE_FMT) ; n = byte_chr(buf, len, ':') ; /* XXX: accepts :, as a valid netstring */ - if (n >= UINT64_FMT) + if (n >= SIZE_FMT) { buffer_unget(b, len) ; return (errno = EPROTO, -1) ; @@ -40,13 +40,13 @@ ssize_t netstring_get (buffer *b, stralloc *sa, size_t *state) if (r <= 0) return r ; } buffer_unget(b, len - n - 1) ; - if (!n || n != uint64_scan(buf, &len)) return (errno = EPROTO, -1) ; + if (!n || n != size_scan(buf, &len)) return (errno = EPROTO, -1) ; if (!stralloc_readyplus(sa, len + 1)) return -1 ; *state = len + 1 ; } { size_t w = 0 ; - register ssize_t r = buffer_getall(b, sa->s + sa->len, *state, &w) ; + int r = buffer_getall(b, sa->s + sa->len, *state, &w) ; sa->len += w ; *state -= w ; if (r <= 0) return r ; diff --git a/src/libstddjb/openreadclose.c b/src/libstddjb/openreadclose.c deleted file mode 100644 index cf9a736..0000000 --- a/src/libstddjb/openreadclose.c +++ /dev/null @@ -1,21 +0,0 @@ -/* ISC license. */ - -#include <errno.h> -#include <skalibs/stralloc.h> -#include <skalibs/djbunix.h> - -int openreadclose (char const *fn, stralloc *sa, unsigned int bufsize) -{ - int fd = open_readb(fn) ; - if (fd == -1) return (errno == ENOENT) ? 0 : -1 ; - if (!slurp(sa, fd)) - { - register int e = errno ; - fd_close(fd) ; - errno = e ; - return -1 ; - } - fd_close(fd) ; - (void)bufsize ; - return 0 ; -} diff --git a/src/libstddjb/openreadfileclose.c b/src/libstddjb/openreadfileclose.c index 90e6b47..b78232c 100644 --- a/src/libstddjb/openreadfileclose.c +++ b/src/libstddjb/openreadfileclose.c @@ -7,9 +7,9 @@ #include <skalibs/stralloc.h> #include <skalibs/djbunix.h> -int openreadfileclose (char const *file, stralloc *sa, unsigned int limit) +int openreadfileclose (char const *file, stralloc *sa, size_t limit) { - unsigned int n ; + size_t n ; int fd = open_readb(file) ; if (fd < 0) return 0 ; { @@ -20,7 +20,7 @@ int openreadfileclose (char const *file, stralloc *sa, unsigned int limit) if (limit && (limit < n)) n = limit ; if (!stralloc_ready_tuned(sa, sa->len + n, 0, 0, 1)) goto err ; { - register unsigned int r = allread(fd, sa->s + sa->len, n) ; + size_t r = allread(fd, sa->s + sa->len, n) ; sa->len += r ; if (r < n) goto err ; } @@ -29,7 +29,7 @@ int openreadfileclose (char const *file, stralloc *sa, unsigned int limit) err: { - register int e = errno ; + int e = errno ; fd_close(fd) ; errno = e ; } diff --git a/src/libstddjb/openreadnclose.c b/src/libstddjb/openreadnclose.c index 40edea9..fcecedc 100644 --- a/src/libstddjb/openreadnclose.c +++ b/src/libstddjb/openreadnclose.c @@ -1,27 +1,28 @@ /* ISC license. */ +#include <sys/types.h> #include <errno.h> #include <skalibs/allreadwrite.h> #include <skalibs/djbunix.h> -static int readnclose (int fd, char *s, unsigned int n) +static ssize_t readnclose (int fd, char *s, size_t n) { - register int r = allread(fd, s, n) ; - register int e = errno ; + ssize_t r = allread(fd, s, n) ; + int e = errno ; fd_close(fd) ; - if ((r > 0) && (r < (int)n)) e = EPIPE ; + if ((r > 0) && (r < (ssize_t)n)) e = EPIPE ; errno = e ; return r ; } -int openreadnclose (char const *file, char *s, unsigned int n) +ssize_t openreadnclose (char const *file, char *s, size_t n) { - register int fd = open_readb(file) ; + int fd = open_readb(file) ; return fd < 0 ? fd : readnclose(fd, s, n) ; } -int openreadnclose_nb (char const *file, char *s, unsigned int n) +ssize_t openreadnclose_nb (char const *file, char *s, size_t n) { - register int fd = open_read(file) ; + int fd = open_read(file) ; return fd < 0 ? fd : readnclose(fd, s, n) ; } diff --git a/src/libstddjb/openwritenclose_suffix.c b/src/libstddjb/openwritenclose_suffix.c index 1c538ed..8608810 100644 --- a/src/libstddjb/openwritenclose_suffix.c +++ b/src/libstddjb/openwritenclose_suffix.c @@ -1,24 +1,25 @@ /* ISC license. */ +#include <sys/types.h> +#include <string.h> #include <errno.h> #include <unistd.h> -#include <stdio.h> /* for rename() */ -#include <skalibs/uint64.h> -#include <skalibs/bytestr.h> +#include <stdio.h> #include <skalibs/djbunix.h> -int openwritenclose_suffix_internal (char const *fn, char const *s, unsigned int n, uint64 *dev, uint64 *ino, int dosync, char const *suffix) +int openwritenclose_suffix_internal (char const *fn, char const *s, size_t n, dev_t *dev, ino_t *ino, int dosync, char const *suffix) { - uint64 tmpdev, tmpino ; - unsigned int len = str_len(fn) ; - unsigned int suffixlen = str_len(suffix) ; + dev_t tmpdev ; + ino_t tmpino ; + size_t len = strlen(fn) ; + size_t suffixlen = strlen(suffix) ; char tmp[len + suffixlen + 1] ; - byte_copy(tmp, len, fn) ; - byte_copy(tmp + len, suffixlen + 1, suffix) ; + memcpy(tmp, fn, len) ; + memcpy(tmp + len, suffix, suffixlen + 1) ; if (!openwritenclose_unsafe_internal(tmp, s, n, dev ? &tmpdev : 0, ino ? &tmpino : 0, dosync)) return 0 ; if (rename(tmp, fn) < 0) { - register int e = errno ; + int e = errno ; unlink(tmp) ; errno = e ; return 0 ; diff --git a/src/libstddjb/openwritenclose_unsafe.c b/src/libstddjb/openwritenclose_unsafe.c index 427f6a6..3276c3f 100644 --- a/src/libstddjb/openwritenclose_unsafe.c +++ b/src/libstddjb/openwritenclose_unsafe.c @@ -4,11 +4,10 @@ #include <sys/stat.h> #include <errno.h> #include <unistd.h> -#include <skalibs/uint64.h> #include <skalibs/allreadwrite.h> #include <skalibs/djbunix.h> -int openwritenclose_unsafe_internal (char const *fn, char const *s, unsigned int len, uint64 *dev, uint64 *ino, int dosync) +int openwritenclose_unsafe_internal (char const *fn, char const *s, size_t len, dev_t *dev, ino_t *ino, int dosync) { struct stat st ; int fd = open_trunc(fn) ; @@ -17,13 +16,13 @@ int openwritenclose_unsafe_internal (char const *fn, char const *s, unsigned int if ((dev || ino) && (fstat(fd, &st) < 0)) goto fail ; if (dosync && (fd_sync(fd) < 0) && (errno != EINVAL)) goto fail ; fd_close(fd) ; - if (dev) *dev = (uint64)st.st_dev ; - if (ino) *ino = (uint64)st.st_ino ; + if (dev) *dev = st.st_dev ; + if (ino) *ino = st.st_ino ; return 1 ; fail: { - register int e = errno ; + int e = errno ; fd_close(fd) ; unlink(fn) ; errno = e ; diff --git a/src/libstddjb/openwritevnclose_suffix.c b/src/libstddjb/openwritevnclose_suffix.c index 0440960..d0185e6 100644 --- a/src/libstddjb/openwritevnclose_suffix.c +++ b/src/libstddjb/openwritevnclose_suffix.c @@ -1,25 +1,26 @@ /* ISC license. */ +#include <sys/types.h> +#include <sys/uio.h> +#include <string.h> #include <errno.h> #include <unistd.h> #include <stdio.h> -#include <skalibs/uint64.h> -#include <skalibs/bytestr.h> -#include <skalibs/siovec.h> #include <skalibs/djbunix.h> -int openwritevnclose_suffix_internal (char const *fn, siovec_t const *v, unsigned int n, uint64 *dev, uint64 *ino, int dosync, char const *suffix) +int openwritevnclose_suffix_internal (char const *fn, struct iovec const *v, unsigned int n, dev_t *dev, ino_t *ino, int dosync, char const *suffix) { - uint64 tmpdev, tmpino ; - unsigned int len = str_len(fn) ; - unsigned int suffixlen = str_len(suffix) ; + dev_t tmpdev ; + ino_t tmpino ; + size_t len = strlen(fn) ; + size_t suffixlen = strlen(suffix) ; char tmp[len + suffixlen + 1] ; - byte_copy(tmp, len, fn) ; - byte_copy(tmp + len, suffixlen + 1, suffix) ; + memcpy(tmp, fn, len) ; + memcpy(tmp + len, suffix, suffixlen + 1) ; if (!openwritevnclose_unsafe_internal(tmp, v, n, dev ? &tmpdev : 0, ino ? &tmpino : 0, dosync)) return 0 ; if (rename(tmp, fn) < 0) { - register int e = errno ; + int e = errno ; unlink(tmp) ; errno = e ; return 0 ; diff --git a/src/libstddjb/openwritevnclose_unsafe.c b/src/libstddjb/openwritevnclose_unsafe.c index feb2ae5..19c5f88 100644 --- a/src/libstddjb/openwritevnclose_unsafe.c +++ b/src/libstddjb/openwritevnclose_unsafe.c @@ -1,15 +1,15 @@ /* ISC license. */ #include <sys/types.h> +#include <sys/uio.h> #include <sys/stat.h> #include <errno.h> #include <unistd.h> -#include <skalibs/uint64.h> #include <skalibs/allreadwrite.h> #include <skalibs/siovec.h> #include <skalibs/djbunix.h> -int openwritevnclose_unsafe_internal (char const *fn, siovec_t const *v, unsigned int vlen, uint64 *dev, uint64 *ino, int dosync) +int openwritevnclose_unsafe_internal (char const *fn, struct iovec const *v, unsigned int vlen, dev_t *dev, ino_t *ino, int dosync) { struct stat st ; int fd = open_trunc(fn) ; @@ -18,13 +18,13 @@ int openwritevnclose_unsafe_internal (char const *fn, siovec_t const *v, unsigne if ((dev || ino) && (fstat(fd, &st) < 0)) goto fail ; if (dosync && (fd_sync(fd) < 0) && (errno != EINVAL)) goto fail ; fd_close(fd) ; - if (dev) *dev = (uint64)st.st_dev ; - if (ino) *ino = (uint64)st.st_ino ; + if (dev) *dev = st.st_dev ; + if (ino) *ino = st.st_ino ; return 1 ; fail: { - register int e = errno ; + int e = errno ; fd_close(fd) ; unlink(fn) ; errno = e ; diff --git a/src/libstddjb/pathexec_fromenv.c b/src/libstddjb/pathexec_fromenv.c index df8b0e6..f9c973b 100644 --- a/src/libstddjb/pathexec_fromenv.c +++ b/src/libstddjb/pathexec_fromenv.c @@ -11,7 +11,7 @@ int pathexec_env (char const *s, char const *t) /* historic, bad name */ return env_addmodif(&plus, s, t) ; } -void pathexec_fromenv (char const *const *argv, char const *const *envp, unsigned int envlen) +void pathexec_fromenv (char const *const *argv, char const *const *envp, size_t envlen) { pathexec_r(argv, envp, envlen, plus.s, plus.len) ; } diff --git a/src/libstddjb/pathexec_r.c b/src/libstddjb/pathexec_r.c index eb4a894..38420cb 100644 --- a/src/libstddjb/pathexec_r.c +++ b/src/libstddjb/pathexec_r.c @@ -1,8 +1,9 @@ /* ISC license. */ +#include <sys/types.h> #include <skalibs/djbunix.h> -void pathexec_r (char const *const *argv, char const *const *envp, unsigned int envlen, char const *modifs, unsigned int modiflen) +void pathexec_r (char const *const *argv, char const *const *envp, size_t envlen, char const *modifs, size_t modiflen) { pathexec_r_name(argv[0], argv, envp, envlen, modifs, modiflen) ; } diff --git a/src/libstddjb/pathexec_r_name.c b/src/libstddjb/pathexec_r_name.c index c5caf4e..68016e5 100644 --- a/src/libstddjb/pathexec_r_name.c +++ b/src/libstddjb/pathexec_r_name.c @@ -1,12 +1,13 @@ /* ISC license. */ +#include <sys/types.h> #include <skalibs/bytestr.h> #include <skalibs/env.h> #include <skalibs/djbunix.h> -void pathexec_r_name (char const *file, char const *const *argv, char const *const *envp, unsigned int envlen, char const *modifs, unsigned int modiflen) +void pathexec_r_name (char const *file, char const *const *argv, char const *const *envp, size_t envlen, char const *modifs, size_t modiflen) { - unsigned int n = envlen + 1 + byte_count(modifs, modiflen, '\0') ; + size_t n = envlen + 1 + byte_count(modifs, modiflen, '\0') ; char const *v[n] ; if (env_merge(v, n, envp, envlen, modifs, modiflen)) pathexec_run(file, argv, v) ; diff --git a/src/libstddjb/pathexec_run.c b/src/libstddjb/pathexec_run.c index ced2ae6..4d9b291 100644 --- a/src/libstddjb/pathexec_run.c +++ b/src/libstddjb/pathexec_run.c @@ -6,7 +6,7 @@ void pathexec_run (char const *file, char const *const *argv, char const *const *envp) { - register char const *path = env_get("PATH") ; + char const *path = env_get("PATH") ; if (!path) path = SKALIBS_DEFAULTPATH ; execvep(file, argv, envp, path) ; } diff --git a/src/libstddjb/rm_rf_in_tmp.c b/src/libstddjb/rm_rf_in_tmp.c index 8a0a9ec..cc13e95 100644 --- a/src/libstddjb/rm_rf_in_tmp.c +++ b/src/libstddjb/rm_rf_in_tmp.c @@ -1,19 +1,18 @@ /* ISC license. */ -#include <sys/types.h> #include <unistd.h> #include <errno.h> -#include <skalibs/bytestr.h> +#include <string.h> #include <skalibs/stralloc.h> #include <skalibs/direntry.h> #include <skalibs/djbunix.h> -static int rmstarindir (DIR *dir, stralloc *tmp, unsigned int ipos) /* WARNING: closes dir */ +static int rmstarindir (DIR *dir, stralloc *tmp, size_t ipos) /* WARNING: closes dir */ { - unsigned int tmpbase = tmp->len ; + size_t tmpbase = tmp->len ; for (;;) { - register direntry *d ; + direntry *d ; errno = 0 ; d = readdir(dir) ; if (!d) break ; @@ -26,16 +25,16 @@ static int rmstarindir (DIR *dir, stralloc *tmp, unsigned int ipos) /* WARNING: dir_close(dir) ; { - unsigned int tmpstop = tmp->len ; - unsigned int fnbase = str_len(tmp->s + ipos) ; - unsigned int i = tmpbase ; + size_t tmpstop = tmp->len ; + size_t fnbase = strlen(tmp->s + ipos) ; + size_t i = tmpbase ; if (!stralloc_readyplus(tmp, fnbase+1)) goto err ; stralloc_catb(tmp, tmp->s + ipos, fnbase) ; stralloc_catb(tmp, "/", 1) ; fnbase = tmp->len ; for (; i < tmpstop ; i += tmp->len - fnbase) { - register unsigned int n = str_len(tmp->s + i) ; + size_t n = strlen(tmp->s + i) ; tmp->len = fnbase ; if (!stralloc_readyplus(tmp, n+1)) goto err ; stralloc_catb(tmp, tmp->s + i, n+1) ; @@ -47,7 +46,7 @@ static int rmstarindir (DIR *dir, stralloc *tmp, unsigned int ipos) /* WARNING: closeanderr: { - register int e = errno ; + int e = errno ; dir_close(dir) ; errno = e ; } @@ -56,14 +55,14 @@ err: return -1 ; } -int rm_rf_in_tmp (stralloc *tmp, unsigned int ipos) +int rm_rf_in_tmp (stralloc *tmp, size_t ipos) { if (unlink(tmp->s + ipos) == 0) return 0 ; if (errno == ENOENT) return 0 ; if ((errno != EISDIR) && (errno != EPERM)) return -1 ; { - register int h = (errno == EPERM) ; - register DIR *dir = opendir(tmp->s + ipos) ; + int h = (errno == EPERM) ; + DIR *dir = opendir(tmp->s + ipos) ; if (!dir) { if (h && (errno == ENOTDIR)) errno = EPERM ; @@ -76,11 +75,11 @@ int rm_rf_in_tmp (stralloc *tmp, unsigned int ipos) int rmstar_tmp (char const *dirname, stralloc *tmp) { - unsigned int tmpbase = tmp->len ; + size_t tmpbase = tmp->len ; if (!stralloc_cats(tmp, dirname)) return -1 ; if (!stralloc_0(tmp)) goto err ; { - register DIR *dir = opendir(dirname) ; + DIR *dir = opendir(dirname) ; if (!dir) goto err ; if (rmstarindir(dir, tmp, tmpbase) == -1) goto err ; } diff --git a/src/libstddjb/rm_rf_tmp.c b/src/libstddjb/rm_rf_tmp.c index 6e434d7..d1a8b1a 100644 --- a/src/libstddjb/rm_rf_tmp.c +++ b/src/libstddjb/rm_rf_tmp.c @@ -1,11 +1,12 @@ /* ISC license. */ +#include <sys/types.h> #include <skalibs/stralloc.h> #include <skalibs/djbunix.h> int rm_rf_tmp (char const *filename, stralloc *tmp) { - unsigned int tmpbase = tmp->len ; + size_t tmpbase = tmp->len ; if (!stralloc_cats(tmp, filename)) return -1 ; if (!stralloc_0(tmp)) goto err ; if (rm_rf_in_tmp(tmp, tmpbase) == -1) goto err ; diff --git a/src/libstddjb/sabasename.c b/src/libstddjb/sabasename.c index 829b2a7..8d9b6fc 100644 --- a/src/libstddjb/sabasename.c +++ b/src/libstddjb/sabasename.c @@ -1,16 +1,17 @@ /* ISC license. */ +#include <sys/types.h> #include <skalibs/bytestr.h> #include <skalibs/stralloc.h> #include <skalibs/djbunix.h> -int sabasename (stralloc *sa, char const *s, unsigned int len) +int sabasename (stralloc *sa, char const *s, size_t len) { if (!len) return stralloc_catb(sa, ".", 1) ; while (len && (s[len-1] == '/')) len-- ; if (!len) return stralloc_catb(sa, "/", 1) ; { - register unsigned int i = byte_rchr(s, len, '/') ; + size_t i = byte_rchr(s, len, '/') ; i = (i == len) ? 0 : i+1 ; return stralloc_catb(sa, s + i, len - i) ; } diff --git a/src/libstddjb/sadirname.c b/src/libstddjb/sadirname.c index 9fc4802..ac818e8 100644 --- a/src/libstddjb/sadirname.c +++ b/src/libstddjb/sadirname.c @@ -1,16 +1,17 @@ /* ISC license. */ +#include <sys/types.h> #include <skalibs/bytestr.h> #include <skalibs/stralloc.h> #include <skalibs/djbunix.h> -int sadirname (stralloc *sa, char const *s, unsigned int len) +int sadirname (stralloc *sa, char const *s, size_t len) { if (!len) return stralloc_catb(sa, ".", 1) ; while (len && (s[len-1] == '/')) len-- ; if (!len) return stralloc_catb(sa, "/", 1) ; { - register unsigned int i = byte_rchr(s, len, '/') ; + size_t i = byte_rchr(s, len, '/') ; return (i == len) ? stralloc_catb(sa, ".", 1) : (i == 0) ? stralloc_catb(sa, "/", 1) : stralloc_catb(sa, s, i) ; diff --git a/src/libstddjb/sig_name.c b/src/libstddjb/sig_name.c index dd5a456..0679055 100644 --- a/src/libstddjb/sig_name.c +++ b/src/libstddjb/sig_name.c @@ -5,7 +5,7 @@ char const *sig_name (int sig) { - register sigtable_t const *p = skalibs_sigtable ; + sigtable_t const *p = skalibs_sigtable ; for (; p->number ; p++) if (sig == p->number) break ; return p->number ? p->name : "???" ; } diff --git a/src/libstddjb/siovec_bytechr.c b/src/libstddjb/siovec_bytechr.c index a825488..8c7e78c 100644 --- a/src/libstddjb/siovec_bytechr.c +++ b/src/libstddjb/siovec_bytechr.c @@ -1,17 +1,19 @@ /* ISC license. */ +#include <sys/types.h> +#include <sys/uio.h> #include <skalibs/bytestr.h> #include <skalibs/siovec.h> -unsigned int siovec_bytechr (siovec_t const *v, unsigned int n, char c) +size_t siovec_bytechr (struct iovec const *v, unsigned int n, char c) { - unsigned int w = 0 ; + size_t w = 0 ; unsigned int i = 0 ; for (; i < n ; i++) { - register unsigned int pos = byte_chr(v[i].s, v[i].len, c) ; + size_t pos = byte_chr((char const *)v[i].iov_base, v[i].iov_len, c) ; w += pos ; - if (pos < v[i].len) break ; + if (pos < v[i].iov_len) break ; } return w ; } diff --git a/src/libstddjb/siovec_bytein.c b/src/libstddjb/siovec_bytein.c index e9db87d..bcf6e59 100644 --- a/src/libstddjb/siovec_bytein.c +++ b/src/libstddjb/siovec_bytein.c @@ -1,17 +1,19 @@ /* ISC license. */ +#include <sys/types.h> +#include <sys/uio.h> #include <skalibs/bytestr.h> #include <skalibs/siovec.h> -unsigned int siovec_bytein (siovec_t const *v, unsigned int n, char const *sep, unsigned int seplen) +size_t siovec_bytein (struct iovec const *v, unsigned int n, char const *sep, size_t seplen) { - unsigned int w = 0 ; + size_t w = 0 ; unsigned int i = 0 ; for (; i < n ; i++) { - register unsigned int pos = byte_in(v[i].s, v[i].len, sep, seplen) ; + size_t pos = byte_in((char const *)v[i].iov_base, v[i].iov_len, sep, seplen) ; w += pos ; - if (pos < v[i].len) break ; + if (pos < v[i].iov_len) break ; } return w ; } diff --git a/src/libstddjb/siovec_deal.c b/src/libstddjb/siovec_deal.c index fffea92..3f802b9 100644 --- a/src/libstddjb/siovec_deal.c +++ b/src/libstddjb/siovec_deal.c @@ -1,24 +1,26 @@ /* ISC license. */ -#include <skalibs/bytestr.h> +#include <sys/types.h> +#include <sys/uio.h> +#include <string.h> #include <skalibs/siovec.h> -unsigned int siovec_deal (siovec_t const *vj, unsigned int nj, siovec_t const *vi, unsigned int ni) +size_t siovec_deal (struct iovec const *vj, unsigned int nj, struct iovec const *vi, unsigned int ni) { - unsigned int w = 0 ; + size_t w = 0 ; + size_t wi = 0 ; + size_t wj = 0 ; unsigned int i = 0 ; unsigned int j = 0 ; - unsigned int wi = 0 ; - unsigned int wj = 0 ; while (i < ni && j < nj) { - register unsigned int tor = vi[i].len - wi ; - register unsigned int tow = vj[j].len - wj ; - register unsigned int len = tor < tow ? tor : tow ; - byte_copy(vj[j].s + wj, len, vi[i].s + wi) ; + size_t tor = vi[i].iov_len - wi ; + size_t tow = vj[j].iov_len - wj ; + size_t len = tor < tow ? tor : tow ; + memmove((char *)vj[j].iov_base + wj, (char const *)vi[i].iov_base + wi, len) ; wi += len ; wj += len ; w += len ; - if (wi >= vi[i].len) { wi = 0 ; i++ ; } - if (wj >= vj[j].len) { wj = 0 ; j++ ; } + if (wi >= vi[i].iov_len) { wi = 0 ; i++ ; } + if (wj >= vj[j].iov_len) { wj = 0 ; j++ ; } } return w ; } diff --git a/src/libstddjb/siovec_from_iovec.c b/src/libstddjb/siovec_from_iovec.c deleted file mode 100644 index ffc0508..0000000 --- a/src/libstddjb/siovec_from_iovec.c +++ /dev/null @@ -1,14 +0,0 @@ -/* ISC license. */ - -#include <sys/types.h> -#include <sys/uio.h> -#include <skalibs/siovec.h> - -void siovec_from_iovec (siovec_t *v, struct iovec const *iov, unsigned int n) -{ - while (n--) - { - v[n].s = iov[n].iov_base ; - v[n].len = iov[n].iov_len ; - } -} diff --git a/src/libstddjb/siovec_gather.c b/src/libstddjb/siovec_gather.c index 23ae28a..b5fcbb7 100644 --- a/src/libstddjb/siovec_gather.c +++ b/src/libstddjb/siovec_gather.c @@ -1,17 +1,19 @@ /* ISC license. */ -#include <skalibs/bytestr.h> +#include <sys/types.h> +#include <sys/uio.h> +#include <string.h> #include <skalibs/siovec.h> -unsigned int siovec_gather (siovec_t const *v, unsigned int n, char *s, unsigned int max) +size_t siovec_gather (struct iovec const *v, unsigned int n, char *s, size_t max) { - unsigned int w = 0 ; - register unsigned int i = 0 ; + size_t w = 0 ; + unsigned int i = 0 ; for (; i < n && w < max ; i++) { - register unsigned int len = v[i].len ; + size_t len = v[i].iov_len ; if ((w + len) > max) len = max - w ; - byte_copy(s + w, len, v[i].s) ; + memmove(s + w, v[i].iov_base, len) ; w += len ; } return w ; diff --git a/src/libstddjb/siovec_len.c b/src/libstddjb/siovec_len.c index 5d53e53..5465fd7 100644 --- a/src/libstddjb/siovec_len.c +++ b/src/libstddjb/siovec_len.c @@ -1,10 +1,12 @@ /* ISC license. */ +#include <sys/types.h> +#include <sys/uio.h> #include <skalibs/siovec.h> -unsigned int siovec_len (siovec_t const *v, register unsigned int n) +size_t siovec_len (struct iovec const *v, unsigned int n) { - register unsigned int w = 0 ; - while (n--) w += v[n].len ; + size_t w = 0 ; + while (n--) w += v[n].iov_len ; return w ; } diff --git a/src/libstddjb/siovec_scatter.c b/src/libstddjb/siovec_scatter.c index 256bef5..3a583f3 100644 --- a/src/libstddjb/siovec_scatter.c +++ b/src/libstddjb/siovec_scatter.c @@ -1,17 +1,19 @@ /* ISC license. */ -#include <skalibs/bytestr.h> +#include <sys/types.h> +#include <sys/uio.h> +#include <string.h> #include <skalibs/siovec.h> -unsigned int siovec_scatter (siovec_t const *v, unsigned int n, char const *s, unsigned int len) +size_t siovec_scatter (struct iovec const *v, unsigned int n, char const *s, size_t len) { - unsigned int w = 0 ; - register unsigned int i = 0 ; + size_t w = 0 ; + unsigned int i = 0 ; for (; i < n && w < len ; i++) { - register unsigned int chunklen = v[i].len ; + size_t chunklen = v[i].iov_len ; if (w + chunklen > len) chunklen = len - w ; - byte_copy(v[i].s, chunklen, s + w) ; + memmove(v[i].iov_base, s + w, chunklen) ; w += chunklen ; } return w ; diff --git a/src/libstddjb/siovec_seek.c b/src/libstddjb/siovec_seek.c index 34a8918..f03b20a 100644 --- a/src/libstddjb/siovec_seek.c +++ b/src/libstddjb/siovec_seek.c @@ -1,24 +1,26 @@ /* ISC license. */ +#include <sys/types.h> +#include <sys/uio.h> #include <skalibs/bytestr.h> #include <skalibs/siovec.h> -unsigned int siovec_seek (siovec_t *v, unsigned int n, unsigned int len) +size_t siovec_seek (struct iovec *v, unsigned int n, size_t len) { - unsigned int w = 0 ; + size_t w = 0 ; register unsigned int i = 0 ; for (; i < n ; i++) { - if (len < v[i].len) break ; - w += v[i].len ; - len -= v[i].len ; - v[i].s = 0 ; - v[i].len = 0 ; + if (len < v[i].iov_len) break ; + w += v[i].iov_len ; + len -= v[i].iov_len ; + v[i].iov_base = 0 ; + v[i].iov_len = 0 ; } if (i < n) { - v[i].s += len ; - v[i].len -= len ; + v[i].iov_base = (char *)v[i].iov_base + len ; + v[i].iov_len -= len ; w += len ; } return w ; diff --git a/src/libstddjb/siovec_trunc.c b/src/libstddjb/siovec_trunc.c index c09225a..ca40922 100644 --- a/src/libstddjb/siovec_trunc.c +++ b/src/libstddjb/siovec_trunc.c @@ -1,18 +1,19 @@ /* ISC license. */ -#include <skalibs/bytestr.h> +#include <sys/types.h> +#include <sys/uio.h> #include <skalibs/siovec.h> -unsigned int siovec_trunc (siovec_t *v, unsigned int n, unsigned int len) +unsigned int siovec_trunc (struct iovec *v, unsigned int n, size_t len) { - register unsigned int i = siovec_len(v, n) ; - if (i < len) return n ; - len = i - len ; - i = n ; + size_t w = siovec_len(v, n) ; + unsigned int i = n ; + if (w < len) return n ; + len = w - len ; while (len && i--) { - register unsigned int w = len > v[i].len ? v[i].len : len ; - v[i].len -= w ; len -= w ; + w = len > v[i].iov_len ? v[i].iov_len : len ; + v[i].iov_len -= w ; len -= w ; } return i ; } diff --git a/src/libstddjb/skagetln.c b/src/libstddjb/skagetln.c index 05775f6..45d81d8 100644 --- a/src/libstddjb/skagetln.c +++ b/src/libstddjb/skagetln.c @@ -1,5 +1,6 @@ /* ISC license. */ +#include <sys/types.h> #include <errno.h> #include <skalibs/buffer.h> #include <skalibs/stralloc.h> @@ -7,10 +8,10 @@ int skagetln (buffer *b, stralloc *sa, char sep) { - unsigned int start = sa->len ; + size_t start = sa->len ; for (;;) { - register int r = skagetln_nofill(b, sa, sep) ; + ssize_t r = skagetln_nofill(b, sa, sep) ; if (r) return r ; r = buffer_fill(b) ; if (r < 0) return r ; diff --git a/src/libstddjb/skagetln_nofill.c b/src/libstddjb/skagetln_nofill.c index 7e25760..ce28921 100644 --- a/src/libstddjb/skagetln_nofill.c +++ b/src/libstddjb/skagetln_nofill.c @@ -1,5 +1,7 @@ /* ISC license. */ +#include <sys/types.h> +#include <sys/uio.h> #include <skalibs/buffer.h> #include <skalibs/siovec.h> #include <skalibs/stralloc.h> @@ -7,8 +9,8 @@ int skagetln_nofill (buffer *b, stralloc *sa, char sep) { - siovec_t v[2] ; - unsigned int pos ; + struct iovec v[2] ; + size_t pos ; int r ; buffer_rpeek(b, v) ; pos = siovec_bytechr(v, 2, sep) ; diff --git a/src/libstddjb/skagetlnsep.c b/src/libstddjb/skagetlnsep.c index 1d3b4ef..f9813f3 100644 --- a/src/libstddjb/skagetlnsep.c +++ b/src/libstddjb/skagetlnsep.c @@ -1,18 +1,20 @@ /* ISC license. */ +#include <sys/types.h> +#include <sys/uio.h> #include <errno.h> #include <skalibs/buffer.h> #include <skalibs/siovec.h> #include <skalibs/stralloc.h> #include <skalibs/skamisc.h> -int skagetlnsep (buffer *b, stralloc *sa, char const *sep, unsigned int seplen) +int skagetlnsep (buffer *b, stralloc *sa, char const *sep, size_t seplen) { - unsigned int start = sa->len ; + size_t start = sa->len ; for (;;) { - siovec_t v[2] ; - unsigned int pos ; + struct iovec v[2] ; + size_t pos ; int r ; buffer_rpeek(b, v) ; pos = siovec_bytein(v, 2, sep, seplen) ; diff --git a/src/libstddjb/str_cpy.c b/src/libstddjb/str_cpy.c deleted file mode 100644 index 179688c..0000000 --- a/src/libstddjb/str_cpy.c +++ /dev/null @@ -1,16 +0,0 @@ -/* ISC license. */ - -#include <skalibs/config.h> - -#ifdef SKALIBS_FLAG_REPLACE_LIBC - -#include <skalibs/bytestr.h> - -unsigned int str_copy (char *s, char const *t) -{ - register unsigned int len = 0 ; - while ((*s = *t)) (s++, t++, len++) ; - return len ; -} - -#endif diff --git a/src/libstddjb/str_diff.c b/src/libstddjb/str_diff.c deleted file mode 100644 index b85288a..0000000 --- a/src/libstddjb/str_diff.c +++ /dev/null @@ -1,24 +0,0 @@ -/* ISC license. */ - -#include <skalibs/config.h> - -#ifdef SKALIBS_FLAG_REPLACE_LIBC - -#include <skalibs/bytestr.h> - -int str_diff (register char const *s, register char const *t) -{ - register char x ; - - for (;;) - { - x = *s; if (x != *t) break; if (!x) break; ++s; ++t; - x = *s; if (x != *t) break; if (!x) break; ++s; ++t; - x = *s; if (x != *t) break; if (!x) break; ++s; ++t; - x = *s; if (x != *t) break; if (!x) break; ++s; ++t; - } - return ((int)(unsigned int)(unsigned char) x) - - ((int)(unsigned int)(unsigned char) *t) ; -} - -#endif diff --git a/src/libstddjb/str_diffn.c b/src/libstddjb/str_diffn.c deleted file mode 100644 index 28f37f6..0000000 --- a/src/libstddjb/str_diffn.c +++ /dev/null @@ -1,19 +0,0 @@ -/* ISC license. */ - -#include <skalibs/config.h> -#include <skalibs/bytestr.h> - -#ifdef SKALIBS_FLAG_REPLACE_LIBC - -int str_diffn (register char const *s, register char const *t, register unsigned int len) -{ - while (len--) - { - if (*s != *t) return *s - *t ; - if (!*s) break ; - s++ ; t++ ; - } - return 0 ; -} - -#endif diff --git a/src/libstddjb/str_len.c b/src/libstddjb/str_len.c deleted file mode 100644 index 75bd1f2..0000000 --- a/src/libstddjb/str_len.c +++ /dev/null @@ -1,16 +0,0 @@ -/* ISC license. */ - -#include <skalibs/config.h> - -#ifdef SKALIBS_FLAG_REPLACE_LIBC - -#include <skalibs/bytestr.h> - -unsigned int str_len (char const *s) -{ - register unsigned int len = 0 ; - while (*s++) len++ ; - return len ; -} - -#endif diff --git a/src/libstddjb/stralloc_catv.c b/src/libstddjb/stralloc_catv.c index 684829c..a0c50aa 100644 --- a/src/libstddjb/stralloc_catv.c +++ b/src/libstddjb/stralloc_catv.c @@ -3,17 +3,14 @@ #include <sys/types.h> #include <string.h> #include <sys/uio.h> +#include <skalibs/siovec.h> #include <skalibs/stralloc.h> int stralloc_catv (stralloc *sa, struct iovec const *v, unsigned int n) { - register unsigned int i = 0 ; - { - size_t total = 0 ; - for (; i < n ; i++) total += v[i].iov_len ; - if (!stralloc_readyplus(sa, total)) return 0 ; - } - for (i = 0 ; i < n ; i++) + unsigned int i = 0 ; + if (!stralloc_readyplus(sa, siovec_len(v, n))) return 0 ; + for ( ; i < n ; i++) { memmove(sa->s + sa->len, v[i].iov_base, v[i].iov_len) ; sa->len += v[i].iov_len ; diff --git a/src/libstddjb/string_format.c b/src/libstddjb/string_format.c index f81b03d..73c2572 100644 --- a/src/libstddjb/string_format.c +++ b/src/libstddjb/string_format.c @@ -1,5 +1,7 @@ /* ISC license. */ +#include <sys/types.h> +#include <string.h> #include <errno.h> #include <skalibs/bytestr.h> #include <skalibs/stralloc.h> @@ -8,10 +10,10 @@ int string_format (stralloc *sa, char const *vars, char const *format, char cons { static unsigned char const tab[2][4] = { "1442", "4833" } ; char class[256] = "3222222222222222222222222222222222222022222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222" ; - unsigned int varlen = str_len(vars) ; - unsigned int base = sa->len ; + size_t varlen = strlen(vars) ; + size_t base = sa->len ; + size_t state = 0 ; int wasnull = !sa->s ; - unsigned int state = 0 ; for (; state < varlen ; state++) if (class[(unsigned char)vars[state]] == '2') diff --git a/src/libstddjb/string_quote.c b/src/libstddjb/string_quote.c index ed00402..37258c5 100644 --- a/src/libstddjb/string_quote.c +++ b/src/libstddjb/string_quote.c @@ -1,11 +1,12 @@ /* ISC license. */ +#include <sys/types.h> #include <skalibs/stralloc.h> #include <skalibs/skamisc.h> -int string_quote (stralloc *sa, char const *s, unsigned int len) +int string_quote (stralloc *sa, char const *s, size_t len) { - unsigned int base = sa->len ; + size_t base = sa->len ; int wasnull = !sa->s ; if (!stralloc_catb(sa, "\"", 1)) return 0 ; if (!string_quote_nodelim(sa, s, len) || !stralloc_catb(sa, "\"", 1)) diff --git a/src/libstddjb/string_quote_nodelim.c b/src/libstddjb/string_quote_nodelim.c index dfe41ce..26b612f 100644 --- a/src/libstddjb/string_quote_nodelim.c +++ b/src/libstddjb/string_quote_nodelim.c @@ -1,9 +1,10 @@ /* ISC license. */ +#include <sys/types.h> #include <skalibs/stralloc.h> #include <skalibs/skamisc.h> -int string_quote_nodelim (stralloc *sa, char const *s, unsigned int len) +int string_quote_nodelim (stralloc *sa, char const *s, size_t len) { return string_quote_nodelim_mustquote(sa, s, len, "\"", 1) ; } diff --git a/src/libstddjb/string_quote_nodelim_mustquote.c b/src/libstddjb/string_quote_nodelim_mustquote.c index e52bce3..a978921 100644 --- a/src/libstddjb/string_quote_nodelim_mustquote.c +++ b/src/libstddjb/string_quote_nodelim_mustquote.c @@ -1,17 +1,17 @@ /* ISC license. */ +#include <sys/types.h> #include <errno.h> #include <skalibs/bytestr.h> #include <skalibs/fmtscan.h> #include <skalibs/stralloc.h> #include <skalibs/skamisc.h> -int string_quote_nodelim_mustquote (stralloc *sa, char const *s, unsigned int len, char const *delim, unsigned int delimlen) +int string_quote_nodelim_mustquote (stralloc *sa, char const *s, size_t len, char const *delim, size_t delimlen) { char class[256] = "dddddddaaaaaaaddddddddddddddddddcccccccccccccccceeeeeeeeeeccccccccccccccccccccccccccccccccccbcccceeeeeecccccccecccececececcccccddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd" ; - - unsigned int base = sa->len ; - unsigned int i = 0 ; + size_t base = sa->len ; + size_t i = 0 ; int wasnull = !sa->s ; for (; i < delimlen ; i++) diff --git a/src/libstddjb/string_unquote.c b/src/libstddjb/string_unquote.c index f4482ff..4245014 100644 --- a/src/libstddjb/string_unquote.c +++ b/src/libstddjb/string_unquote.c @@ -1,18 +1,19 @@ /* ISC license. */ +#include <sys/types.h> +#include <string.h> #include <errno.h> -#include <skalibs/bytestr.h> #include <skalibs/skamisc.h> -int string_unquote (char *d, unsigned int *w, char const *s, unsigned int len, unsigned int *r) +int string_unquote (char *d, size_t *w, char const *s, size_t len, size_t *r) { if (!len-- || (*s++ != '"')) return (errno = EINVAL, 0) ; { - unsigned int rr, ww ; - char tmp[len] ; + size_t rr, ww ; + char tmp[len ? len : 1] ; if (!string_unquote_withdelim(tmp, &ww, s, len, &rr, "\"", 1)) return 0 ; if (rr == len) return (errno = EPIPE, 0) ; - byte_copy(d, ww, tmp) ; + memcpy(d, tmp, ww) ; *w = ww ; *r = rr + 2 ; } diff --git a/src/libstddjb/string_unquote_nodelim.c b/src/libstddjb/string_unquote_nodelim.c index 1dc90f1..cabe504 100644 --- a/src/libstddjb/string_unquote_nodelim.c +++ b/src/libstddjb/string_unquote_nodelim.c @@ -1,11 +1,12 @@ /* ISC license. */ +#include <sys/types.h> #include <errno.h> #include <skalibs/skamisc.h> -int string_unquote_nodelim (char *d, char const *s, unsigned int len) +ssize_t string_unquote_nodelim (char *d, char const *s, size_t len) { - unsigned int rr, ww ; + size_t rr, ww ; if (!string_unquote_withdelim(d, &ww, s, len, &rr, 0, 0)) return -1 ; - return (int)ww ; + return (ssize_t)ww ; } diff --git a/src/libstddjb/string_unquote_withdelim.c b/src/libstddjb/string_unquote_withdelim.c index dd52dbd..a3e0a68 100644 --- a/src/libstddjb/string_unquote_withdelim.c +++ b/src/libstddjb/string_unquote_withdelim.c @@ -1,5 +1,6 @@ /* ISC license. */ +#include <sys/types.h> #include <errno.h> #include <skalibs/error.h> #include <skalibs/bytestr.h> @@ -14,9 +15,8 @@ #define SYNTAXERROR 0x02 #define BROKENPIPE 0x01 -int string_unquote_withdelim (char *d, unsigned int *w, char const *s, unsigned int len, unsigned int *r, char const *delim, unsigned int delimlen) +int string_unquote_withdelim (char *d, size_t *w, char const *s, size_t len, size_t *r, char const *delim, size_t delimlen) { - register unsigned int i = 0 ; static unsigned char const actions[5][9] = { { 0, 0, PUSH, PUSH, PUSH, PUSH, PUSH, PUSH, 0 }, @@ -34,6 +34,7 @@ int string_unquote_withdelim (char *d, unsigned int *w, char const *s, unsigned { 6, 6, 0, 6, 0, 0, 6, 6, 6 } } ; unsigned char class[256] = "7777777777777777777777777777777777777777777777772555555555777777777777777777777777777777777707777445554777777767776767673777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777" ; + size_t i = 0 ; unsigned char store = 0 ; unsigned char state = 0 ; for (; i < delimlen ; i++) diff --git a/src/libstddjb/touch.c b/src/libstddjb/touch.c index d85c483..d270251 100644 --- a/src/libstddjb/touch.c +++ b/src/libstddjb/touch.c @@ -11,7 +11,7 @@ int touch (char const *file) { - register int fd = open_create(file) ; + int fd = open_create(file) ; if (fd < 0) return 0 ; if (futimens(fd, 0) < 0) return 0 ; fd_close(fd) ; @@ -27,7 +27,7 @@ int touch (char const *file) int touch (char const *file) { - register int fd = open_create(file) ; + int fd = open_create(file) ; if (fd < 0) return 0 ; if (futimes(fd, 0) < 0) return 0 ; fd_close(fd) ; @@ -41,7 +41,7 @@ int touch (char const *file) int touch (char const *file) { - register int fd = open_create(file) ; + int fd = open_create(file) ; if (fd < 0) return 0 ; fd_close(fd) ; if (utimes(file, 0) < 0) return 0 ; diff --git a/src/libstddjb/uncoe.c b/src/libstddjb/uncoe.c index 61593b9..b6bf430 100644 --- a/src/libstddjb/uncoe.c +++ b/src/libstddjb/uncoe.c @@ -5,7 +5,7 @@ int uncoe (int fd) { - register int flags = fcntl(fd, F_GETFD, 0) ; - if (flags < 0) return -1 ; - return fcntl(fd, F_SETFD, flags & ~FD_CLOEXEC) ; + int flags = fcntl(fd, F_GETFD, 0) ; + if (flags < 0) return -1 ; + return fcntl(fd, F_SETFD, flags & ~FD_CLOEXEC) ; } diff --git a/src/libstddjb/vbaprintf.c b/src/libstddjb/vbaprintf.c index efc2bd1..1c23e8c 100644 --- a/src/libstddjb/vbaprintf.c +++ b/src/libstddjb/vbaprintf.c @@ -1,5 +1,6 @@ /* ISC license. */ +#include <sys/types.h> #include <stdarg.h> #include <stdio.h> #include <skalibs/stralloc.h> @@ -16,8 +17,8 @@ int vbaprintf (bufalloc *ba, char const *format, va_list args) va_end(ugly) ; } if (r < 0) return r ; - if (!stralloc_readyplus(&ba->x, (unsigned int)r + 1)) return -1 ; - r = vsnprintf(ba->x.s + ba->x.len, (unsigned int)r + 1, format, args) ; + if (!stralloc_readyplus(&ba->x, (size_t)r + 1)) return -1 ; + r = vsnprintf(ba->x.s + ba->x.len, (size_t)r + 1, format, args) ; if (r > 0) ba->x.len += r ; return r ; } diff --git a/src/libstddjb/vbprintf.c b/src/libstddjb/vbprintf.c index a6a75f3..2f8c13b 100644 --- a/src/libstddjb/vbprintf.c +++ b/src/libstddjb/vbprintf.c @@ -1,5 +1,6 @@ /* ISC license. */ +#include <sys/types.h> #include <stdarg.h> #include <stdio.h> #include <skalibs/buffer.h> @@ -16,8 +17,8 @@ int vbprintf (buffer *b, char const *format, va_list args) } if (r < 0) return r ; { - char buf[(unsigned int)r + 1] ; - r = vsnprintf(buf, (unsigned int)r + 1, format, args) ; + char buf[(size_t)r + 1] ; + r = vsnprintf(buf, (size_t)r + 1, format, args) ; if (r < 0) return r ; if (buffer_put(b, buf, r) < r) return -1 ; } diff --git a/src/libstddjb/wait_nointr.c b/src/libstddjb/wait_nointr.c index 02dcd42..90d6412 100644 --- a/src/libstddjb/wait_nointr.c +++ b/src/libstddjb/wait_nointr.c @@ -7,7 +7,7 @@ pid_t wait_nointr (int *wstat) { - register pid_t r ; + pid_t r ; do r = wait(wstat) ; while ((r == (pid_t)-1) && (errno == EINTR)) ; |