diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2017-02-15 17:40:40 +0000 |
---|---|---|
committer | Laurent Bercot <ska-skaware@skarnet.org> | 2017-02-15 17:40:40 +0000 |
commit | a896ca2a8c617e5e00ffd5fc9e69331ad754e5b3 (patch) | |
tree | f49a8382b9999b5aa00c0885eedd5c5c3a233e55 /src/libstddjb | |
parent | 00c9cb1b22cc17c4db573e0e613a5f116ff0092e (diff) | |
download | skalibs-a896ca2a8c617e5e00ffd5fc9e69331ad754e5b3.tar.xz |
add arc4random_addrandom sysdep; next batch of types changes.
The library isn't supposed to be functional yet: there are
still a lot of type mismatches.
Diffstat (limited to 'src/libstddjb')
67 files changed, 211 insertions, 264 deletions
diff --git a/src/libstddjb/absolutepath_tmp.c b/src/libstddjb/absolutepath_tmp.c index 79a613a..3d3c2b1 100644 --- a/src/libstddjb/absolutepath_tmp.c +++ b/src/libstddjb/absolutepath_tmp.c @@ -1,5 +1,6 @@ /* ISC license. */ +#include <sys/types.h> #include <unistd.h> #include <errno.h> #include <skalibs/bytestr.h> @@ -8,8 +9,8 @@ int sarealpath_tmp (stralloc *sa, char const *path, stralloc *tmp) { - unsigned int tmpbase = tmp->len ; - unsigned int base = sa->len ; + size_t tmpbase = tmp->len ; + size_t base = sa->len ; unsigned int loop = 48 ; int fdhere ; int wasnull = !sa->s ; diff --git a/src/libstddjb/alloc.c b/src/libstddjb/alloc.c index 31e3e05..bf291f0 100644 --- a/src/libstddjb/alloc.c +++ b/src/libstddjb/alloc.c @@ -1,5 +1,6 @@ /* ISC license. */ +#include <sys/types.h> #include <errno.h> #include <stdlib.h> #include <skalibs/sysdeps.h> @@ -13,7 +14,7 @@ # define PLM(...) (bprintf(buffer_2, "%s: debug_alloc: ", PROG), bprintf(buffer_2, __VA_ARGS__), buffer_putflush(buffer_2, "\n", 1)) #endif -aligned_char *alloc (unsigned int n) +aligned_char *alloc (size_t n) { register aligned_char *p = n ? (aligned_char *)malloc(n) : (aligned_char *)alloc_0 ; #ifdef DEBUG_ALLOC @@ -37,7 +38,7 @@ void alloc_free (void *p) errno = e ; } -int alloc_realloc (aligned_char **x, unsigned int n) +int alloc_realloc (aligned_char **x, size_t n) { aligned_char *y = n ? (aligned_char *)realloc(*x, n) : (free(*x), alloc_0) ; #ifdef DEBUG_ALLOC diff --git a/src/libstddjb/allread.c b/src/libstddjb/allread.c index 9f3d3bc..a33b650 100644 --- a/src/libstddjb/allread.c +++ b/src/libstddjb/allread.c @@ -1,8 +1,9 @@ /* ISC license. */ +#include <sys/types.h> #include <skalibs/allreadwrite.h> -unsigned int allread (int fd, char *buf, unsigned int len) +size_t allread (int fd, char *buf, size_t len) { - return allreadwrite(&fd_read, fd, buf, len) ; + return allreadwrite(&fd_readv, fd, buf, len) ; } diff --git a/src/libstddjb/allreadv.c b/src/libstddjb/allreadv.c index 5eb3863..13514cc 100644 --- a/src/libstddjb/allreadv.c +++ b/src/libstddjb/allreadv.c @@ -1,9 +1,10 @@ /* ISC license. */ +#include <sys/types.h> +#include <sys/uio.h> #include <skalibs/allreadwrite.h> -#include <skalibs/siovec.h> -unsigned int allreadv (int fd, siovec_t const *v, unsigned int vlen) +size_t allreadv (int fd, struct iovec const *v, unsigned int vlen) { - return allreadwritev(&fd_readsv, fd, v, vlen) ; + return allreadwritev(&fd_readv, fd, v, vlen) ; } diff --git a/src/libstddjb/allreadwrite.c b/src/libstddjb/allreadwrite.c index a811f69..0e22a8d 100644 --- a/src/libstddjb/allreadwrite.c +++ b/src/libstddjb/allreadwrite.c @@ -1,14 +1,16 @@ /* ISC license. */ +#include <sys/types.h> #include <errno.h> +#include <skalibs/functypes.h> #include <skalibs/allreadwrite.h> -unsigned int allreadwrite (iofunc_t_ref op, int fd, register char *buf, register unsigned int len) +size_t allreadwrite (iofunc_t_ref op, int fd, char *buf, size_t len) { - register unsigned int written = 0 ; + size_t written = 0 ; while (len) { - register int w = (*op)(fd, buf, len) ; + register ssize_t w = (*op)(fd, buf, len) ; if (w <= 0) { if (!w) errno = 0 ; diff --git a/src/libstddjb/allreadwritev.c b/src/libstddjb/allreadwritev.c index 28695a1..2b06ac7 100644 --- a/src/libstddjb/allreadwritev.c +++ b/src/libstddjb/allreadwritev.c @@ -1,18 +1,20 @@ /* ISC license. */ -#include <errno.h> +#include <sys/types.h> +#include <sys/uio.h> +#include <skalibs/functypes.h> #include <skalibs/allreadwrite.h> #include <skalibs/siovec.h> -unsigned int allreadwritev (iovfunc_t_ref op, int fd, siovec_t const *v, unsigned int vlen) +size_t allreadwritev (iovfunc_t_ref op, int fd, struct iovec const *v, unsigned int vlen) { - register unsigned int written = 0 ; - siovec_t vv[vlen] ; - for (; written < vlen ; written++) vv[written] = v[written] ; - written = 0 ; + size_t written = 0 ; + struct iovec vv[vlen] ; + unsigned int i = 0 ; + for (; i < vlen ; i++) vv[i] = v[i] ; while (siovec_len(vv, vlen)) { - register int w = (*op)(fd, vv, vlen) ; + register 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 61c8ad7..f465eb4 100644 --- a/src/libstddjb/allwrite.c +++ b/src/libstddjb/allwrite.c @@ -2,7 +2,7 @@ #include <skalibs/allreadwrite.h> -unsigned int allwrite (int fd, char const *buf, unsigned int len) +size_t allwrite (int fd, char const *buf, size_t len) { return allreadwrite((iofunc_t_ref)&fd_write, fd, (char *)buf, len) ; } diff --git a/src/libstddjb/allwritev.c b/src/libstddjb/allwritev.c index d7195a8..dc343a4 100644 --- a/src/libstddjb/allwritev.c +++ b/src/libstddjb/allwritev.c @@ -1,9 +1,10 @@ /* ISC license. */ +#include <sys/types.h> +#include <sys/uio.h> #include <skalibs/allreadwrite.h> -#include <skalibs/siovec.h> -unsigned int allwritev (int fd, siovec_t const *v, unsigned int vlen) +size_t allwritev (int fd, struct iovec const *v, unsigned int vlen) { - return allreadwritev(&fd_writesv, fd, v, vlen) ; + return allreadwritev(&fd_writev, fd, v, vlen) ; } diff --git a/src/libstddjb/bitarray_and.c b/src/libstddjb/bitarray_and.c index d2f491e..449f300 100644 --- a/src/libstddjb/bitarray_and.c +++ b/src/libstddjb/bitarray_and.c @@ -1,10 +1,11 @@ /* ISC license. */ +#include <sys/types.h> #include <skalibs/bitarray.h> -void bitarray_and (unsigned char *c, unsigned char const *a, unsigned char const *b, unsigned int n) +void bitarray_and (unsigned char *c, unsigned char const *a, unsigned char const *b, size_t n) { - unsigned int len = bitarray_div8(n) ; - register unsigned int i = 0 ; + size_t len = bitarray_div8(n) ; + register size_t i = 0 ; for (; i < len ; i++) c[i] = a[i] & b[i] ; } diff --git a/src/libstddjb/bitarray_clearsetn.c b/src/libstddjb/bitarray_clearsetn.c index d14d6e4..82bff7e 100644 --- a/src/libstddjb/bitarray_clearsetn.c +++ b/src/libstddjb/bitarray_clearsetn.c @@ -1,8 +1,9 @@ /* ISC license. */ +#include <sys/types.h> #include <skalibs/bitarray.h> -void bitarray_clearsetn (register unsigned char *s, register unsigned int a, register unsigned int b, register int h) +void bitarray_clearsetn (register unsigned char *s, register size_t a, register size_t b, register int h) { if (!b) return ; b += a ; @@ -14,7 +15,7 @@ void bitarray_clearsetn (register unsigned char *s, register unsigned int a, reg else { register unsigned char mask = ~((1 << (a & 7)) - 1) ; - register unsigned int i = (a>>3) + 1 ; + register size_t i = (a>>3) + 1 ; if (h) s[a>>3] |= mask ; else s[a>>3] &= ~mask ; mask = h ? 0xff : 0x00 ; for (; i < b>>3 ; i++) s[i] = mask ; diff --git a/src/libstddjb/bitarray_count.c b/src/libstddjb/bitarray_count.c index 724f2b3..47dfda7 100644 --- a/src/libstddjb/bitarray_count.c +++ b/src/libstddjb/bitarray_count.c @@ -1,5 +1,7 @@ /* ISC license. */ +#include <sys/types.h> +#include <skalibs/uint64.h> #include <skalibs/bitarray.h> #define B0(n) n, n+1, n+1, n+2 @@ -7,12 +9,12 @@ #define B2(n) B1(n), B1(n+1), B1(n+1), B1(n+2) #define B3(n) B2(n), B2(n+1), B2(n+1), B2(n+2) -unsigned int bitarray_countones (unsigned char const *c, unsigned int n) +uint64_t bitarray_countones (unsigned char const *c, size_t n) { static unsigned char const table[256] = { B3(0) } ; - unsigned int len = bitarray_div8(n) ; - unsigned int total = 0 ; - register unsigned int i = 0 ; + size_t len = bitarray_div8(n) ; + uint64_t total = 0 ; + register size_t i = 0 ; if (n & 7) len-- ; for (; i < len ; i++) total += table[c[i]] ; if (n & 7) total += table[c[i] & ((1 << (n & 7)) - 1)] ; diff --git a/src/libstddjb/bitarray_firstclear.c b/src/libstddjb/bitarray_firstclear.c index 80b6fbb..869dffe 100644 --- a/src/libstddjb/bitarray_firstclear.c +++ b/src/libstddjb/bitarray_firstclear.c @@ -1,11 +1,12 @@ /* ISC license. */ +#include <sys/types.h> #include <skalibs/bitarray.h> -unsigned int bitarray_firstclear (register unsigned char const *s, unsigned int max) +size_t bitarray_firstclear (register unsigned char const *s, size_t max) { - unsigned int n = bitarray_div8(max) ; - register unsigned int i = 0 ; + size_t n = bitarray_div8(max) ; + register size_t i = 0 ; for (; i < n ; i++) if (s[i] != 0xffU) break ; if (i == n) return max ; i <<= 3 ; diff --git a/src/libstddjb/bitarray_firstclear_skip.c b/src/libstddjb/bitarray_firstclear_skip.c index 8a32dba..ef49ee0 100644 --- a/src/libstddjb/bitarray_firstclear_skip.c +++ b/src/libstddjb/bitarray_firstclear_skip.c @@ -1,11 +1,12 @@ /* ISC license. */ +#include <sys/types.h> #include <skalibs/bitarray.h> -unsigned int bitarray_firstclear_skip (register unsigned char const *s, unsigned int max, unsigned int skip) +size_t bitarray_firstclear_skip (register unsigned char const *s, size_t max, size_t skip) { - register unsigned int i = bitarray_div8(skip) ; - register unsigned int j = i << 3 > max ? max : i << 3 ; + register size_t i = bitarray_div8(skip) ; + register size_t j = i << 3 > max ? max : i << 3 ; if (i && s[i-1] != 0xffU) { while ((skip < j) && bitarray_peek(s, skip)) skip++ ; diff --git a/src/libstddjb/bitarray_firstset.c b/src/libstddjb/bitarray_firstset.c index de3d27e..1422111 100644 --- a/src/libstddjb/bitarray_firstset.c +++ b/src/libstddjb/bitarray_firstset.c @@ -1,11 +1,12 @@ /* ISC license. */ +#include <sys/types.h> #include <skalibs/bitarray.h> -unsigned int bitarray_firstset (register unsigned char const *s, unsigned int max) +size_t bitarray_firstset (register unsigned char const *s, size_t max) { - unsigned int n = bitarray_div8(max) ; - register unsigned int i = 0 ; + size_t n = bitarray_div8(max) ; + register size_t i = 0 ; for (; i < n ; i++) if (s[i]) break ; if (i == n) return max ; i <<= 3 ; diff --git a/src/libstddjb/bitarray_firstset_skip.c b/src/libstddjb/bitarray_firstset_skip.c index 2f269cf..3689375 100644 --- a/src/libstddjb/bitarray_firstset_skip.c +++ b/src/libstddjb/bitarray_firstset_skip.c @@ -1,11 +1,12 @@ /* ISC license. */ +#include <sys/types.h> #include <skalibs/bitarray.h> -unsigned int bitarray_firstset_skip (register unsigned char const *s, unsigned int max, unsigned int skip) +size_t bitarray_firstset_skip (register unsigned char const *s, size_t max, size_t skip) { - register unsigned int i = bitarray_div8(skip) ; - register unsigned int j = i << 3 > max ? max : i << 3 ; + register size_t i = bitarray_div8(skip) ; + register size_t j = i << 3 > max ? max : i << 3 ; if (i && s[i-1]) { while ((skip < j) && !bitarray_peek(s, skip)) skip++ ; diff --git a/src/libstddjb/bitarray_not.c b/src/libstddjb/bitarray_not.c index de37b9f..06da25a 100644 --- a/src/libstddjb/bitarray_not.c +++ b/src/libstddjb/bitarray_not.c @@ -1,8 +1,9 @@ /* ISC license. */ +#include <sys/types.h> #include <skalibs/bitarray.h> -void bitarray_not (register unsigned char *s, register unsigned int a, register unsigned int b) +void bitarray_not (register unsigned char *s, register size_t a, register size_t b) { if (!b) return ; b += a ; @@ -10,7 +11,7 @@ void bitarray_not (register unsigned char *s, register unsigned int a, register s[a>>3] ^= ((1 << (a & 7)) - 1) ^ ((a << (b & 7)) - 1) ; else { - register unsigned int i = (a>>3) + 1 ; + register size_t i = (a>>3) + 1 ; s[a>>3] ^= ~((1 << (a & 7)) - 1) ; for (; i < (b>>3) ; i++) s[i] = ~s[i] ; s[b>>3] ^= (1 << (b & 7)) - 1 ; diff --git a/src/libstddjb/bitarray_or.c b/src/libstddjb/bitarray_or.c index 9e9e6b3..1220ed2 100644 --- a/src/libstddjb/bitarray_or.c +++ b/src/libstddjb/bitarray_or.c @@ -1,10 +1,11 @@ /* ISC license. */ +#include <sys/types.h> #include <skalibs/bitarray.h> -void bitarray_or (unsigned char *c, unsigned char const *a, unsigned char const *b, unsigned int n) +void bitarray_or (unsigned char *c, unsigned char const *a, unsigned char const *b, size_t n) { - unsigned int len = bitarray_div8(n) ; - register unsigned int i = 0 ; + size_t len = bitarray_div8(n) ; + register size_t i = 0 ; for (; i < len ; i++) c[i] = a[i] | b[i] ; } diff --git a/src/libstddjb/bitarray_testandpoke.c b/src/libstddjb/bitarray_testandpoke.c index 5075f1d..5b13b7a 100644 --- a/src/libstddjb/bitarray_testandpoke.c +++ b/src/libstddjb/bitarray_testandpoke.c @@ -1,8 +1,9 @@ /* ISC license. */ +#include <sys/types.h> #include <skalibs/bitarray.h> -int bitarray_testandpoke (register unsigned char *s, register unsigned int n, register int h) +int bitarray_testandpoke (register unsigned char *s, register size_t n, register int h) { register unsigned char mask = 1 << (n & 7) ; register unsigned char c = s[n>>3] ; diff --git a/src/libstddjb/bitarray_xor.c b/src/libstddjb/bitarray_xor.c index 8b16f25..dde5dc7 100644 --- a/src/libstddjb/bitarray_xor.c +++ b/src/libstddjb/bitarray_xor.c @@ -1,10 +1,11 @@ /* ISC license. */ +#include <sys/types.h> #include <skalibs/bitarray.h> -void bitarray_xor (unsigned char *c, unsigned char const *a, unsigned char const *b, unsigned int n) +void bitarray_xor (unsigned char *c, unsigned char const *a, unsigned char const *b, size_t n) { - unsigned int len = bitarray_div8(n) ; - register unsigned int i = 0 ; + size_t len = bitarray_div8(n) ; + register size_t i = 0 ; for (; i < len ; i++) c[i] = a[i] ^ b[i] ; } diff --git a/src/libstddjb/bufalloc_clean.c b/src/libstddjb/bufalloc_clean.c index 79b5880..2b78f39 100644 --- a/src/libstddjb/bufalloc_clean.c +++ b/src/libstddjb/bufalloc_clean.c @@ -1,13 +1,13 @@ /* ISC license. */ -#include <skalibs/bytestr.h> +#include <string.h> #include <skalibs/bufalloc.h> void bufalloc_clean (register bufalloc *ba) { if (ba->p) { - byte_copy(ba->x.s, ba->x.len - ba->p, ba->x.s + ba->p) ; + memmove(ba->x.s, ba->x.s + ba->p, ba->x.len - ba->p) ; ba->x.len -= ba->p ; ba->p = 0 ; } diff --git a/src/libstddjb/bufalloc_flush.c b/src/libstddjb/bufalloc_flush.c index e6ddfc2..b6de51e 100644 --- a/src/libstddjb/bufalloc_flush.c +++ b/src/libstddjb/bufalloc_flush.c @@ -1,5 +1,6 @@ /* ISC license. */ +#include <skalibs/functypes.h> #include <skalibs/allreadwrite.h> #include <skalibs/bufalloc.h> diff --git a/src/libstddjb/bufalloc_getlen.c b/src/libstddjb/bufalloc_getlen.c index 696e41d..600e2ab 100644 --- a/src/libstddjb/bufalloc_getlen.c +++ b/src/libstddjb/bufalloc_getlen.c @@ -1,8 +1,9 @@ /* ISC license. */ +#include <sys/types.h> #include <skalibs/bufalloc.h> -unsigned int bufalloc_getlen (bufalloc const *ba) +size_t bufalloc_getlen (bufalloc const *ba) { return bufalloc_len(ba) ; } diff --git a/src/libstddjb/bufalloc_init.c b/src/libstddjb/bufalloc_init.c index 913dabb..d6a89da 100644 --- a/src/libstddjb/bufalloc_init.c +++ b/src/libstddjb/bufalloc_init.c @@ -1,9 +1,10 @@ /* ISC license. */ +#include <sys/types.h> #include <skalibs/stralloc.h> #include <skalibs/bufalloc.h> -void bufalloc_init (bufalloc *ba, int (*op)(int, char const *, unsigned int), int fd) +void bufalloc_init (bufalloc *ba, int (*op)(int, char const *, size_t), int fd) { ba->x = stralloc_zero ; ba->op = op ; diff --git a/src/libstddjb/buffer_0.c b/src/libstddjb/buffer_0.c index 5d40465..d1b4688 100644 --- a/src/libstddjb/buffer_0.c +++ b/src/libstddjb/buffer_0.c @@ -6,4 +6,4 @@ #include <skalibs/buffer.h> static char buf[BUFFER_INSIZE] ; -buffer buffer_0_ = BUFFER_INIT(&fd_readsv, 0, buf, BUFFER_INSIZE) ; +buffer buffer_0_ = BUFFER_INIT(&fd_readv, 0, buf, BUFFER_INSIZE) ; diff --git a/src/libstddjb/buffer_0small.c b/src/libstddjb/buffer_0small.c index 7537dd6..203908c 100644 --- a/src/libstddjb/buffer_0small.c +++ b/src/libstddjb/buffer_0small.c @@ -6,4 +6,4 @@ #include <skalibs/buffer.h> static char buf[BUFFER_INSIZE_SMALL] ; -buffer buffer_0small_ = BUFFER_INIT(&fd_readsv, 0, buf, BUFFER_INSIZE_SMALL) ; +buffer buffer_0small_ = BUFFER_INIT(&fd_readv, 0, buf, BUFFER_INSIZE_SMALL) ; diff --git a/src/libstddjb/buffer_1.c b/src/libstddjb/buffer_1.c index 46d9647..0def179 100644 --- a/src/libstddjb/buffer_1.c +++ b/src/libstddjb/buffer_1.c @@ -6,4 +6,4 @@ #include <skalibs/buffer.h> static char buf[BUFFER_OUTSIZE] ; -buffer buffer_1_ = BUFFER_INIT(&fd_writesv, 1, buf, BUFFER_OUTSIZE) ; +buffer buffer_1_ = BUFFER_INIT(&fd_writev, 1, buf, BUFFER_OUTSIZE) ; diff --git a/src/libstddjb/buffer_1small.c b/src/libstddjb/buffer_1small.c index 2bf13e6..27ba875 100644 --- a/src/libstddjb/buffer_1small.c +++ b/src/libstddjb/buffer_1small.c @@ -6,4 +6,4 @@ #include <skalibs/buffer.h> static char buf[BUFFER_OUTSIZE_SMALL] ; -buffer buffer_1small_ = BUFFER_INIT(&fd_writesv, 1, buf, BUFFER_OUTSIZE_SMALL) ; +buffer buffer_1small_ = BUFFER_INIT(&fd_writev, 1, buf, BUFFER_OUTSIZE_SMALL) ; diff --git a/src/libstddjb/buffer_2.c b/src/libstddjb/buffer_2.c index 8bf9d63..145d424 100644 --- a/src/libstddjb/buffer_2.c +++ b/src/libstddjb/buffer_2.c @@ -6,4 +6,4 @@ #include <skalibs/buffer.h> static char buf[BUFFER_ERRSIZE] ; -buffer buffer_2_ = BUFFER_INIT(&fd_writesv, 2, buf, BUFFER_ERRSIZE) ; +buffer buffer_2_ = BUFFER_INIT(&fd_writev, 2, buf, BUFFER_ERRSIZE) ; diff --git a/src/libstddjb/buffer_flush1read.c b/src/libstddjb/buffer_flush1read.c index aaa2869..0384602 100644 --- a/src/libstddjb/buffer_flush1read.c +++ b/src/libstddjb/buffer_flush1read.c @@ -1,11 +1,12 @@ /* ISC license. */ +#include <sys/types.h> +#include <sys/uio.h> #include <skalibs/allreadwrite.h> #include <skalibs/buffer.h> -#include <skalibs/siovec.h> -int buffer_flush1read (int fd, siovec_t const *v, unsigned int n) +ssize_t buffer_flush1read (int fd, struct iovec const *v, unsigned int n) { if (!buffer_flush(buffer_1)) return -1 ; - return fd_readsv(fd, v, n) ; + return fd_readv(fd, v, n) ; } diff --git a/src/libstddjb/byte_chr.c b/src/libstddjb/byte_chr.c index 45ad543..d24e92d 100644 --- a/src/libstddjb/byte_chr.c +++ b/src/libstddjb/byte_chr.c @@ -1,26 +1,11 @@ /* ISC license. */ -#include <skalibs/config.h> -#include <skalibs/bytestr.h> - -#ifndef SKALIBS_FLAG_REPLACE_LIBC - +#include <sys/types.h> #include <string.h> +#include <skalibs/bytestr.h> -unsigned int byte_chr (char const *s, unsigned int n, int c) +size_t byte_chr (char const *s, size_t n, int c) { register void *p = memchr(s, c, n) ; - return p ? (unsigned int)((char *)p - s) : n ; + return p ? (char *)p - s : n ; } - -#else - -unsigned int byte_chr (char const *s, unsigned int n, int c) -{ - register unsigned int i = 0 ; - register char ch = c ; - for (; i < n && *s++ != ch ; i++) ; - return i ; -} - -#endif diff --git a/src/libstddjb/byte_count.c b/src/libstddjb/byte_count.c index 5e3f8af..a09e044 100644 --- a/src/libstddjb/byte_count.c +++ b/src/libstddjb/byte_count.c @@ -1,10 +1,11 @@ /* ISC license. */ +#include <sys/types.h> #include <skalibs/bytestr.h> -unsigned int byte_count (register char const *s, register unsigned int len, register char b) +size_t byte_count (char const *s, size_t len, char b) { - register unsigned int n = 0 ; + size_t n = 0 ; while (len--) if (*s++ == b) n++ ; return n ; } diff --git a/src/libstddjb/byte_in.c b/src/libstddjb/byte_in.c index 60625c5..cb6e5bc 100644 --- a/src/libstddjb/byte_in.c +++ b/src/libstddjb/byte_in.c @@ -1,8 +1,9 @@ /* ISC license. */ +#include <sys/types.h> #include <skalibs/bytestr.h> -unsigned int byte_in (char const *s, register unsigned int n, register char const *sep, register unsigned int len) +size_t byte_in (char const *s, size_t n, char const *sep, size_t len) { register char const *t = s ; while (n--) diff --git a/src/libstddjb/byte_rchr.c b/src/libstddjb/byte_rchr.c index 3564c36..66fbf27 100644 --- a/src/libstddjb/byte_rchr.c +++ b/src/libstddjb/byte_rchr.c @@ -1,11 +1,12 @@ /* ISC license. */ +#include <sys/types.h> #include <skalibs/bytestr.h> -unsigned int byte_rchr (register char const *s, unsigned int n, int c) +size_t byte_rchr (char const *s, size_t n, int c) { - register unsigned int i = n ; - register char ch = c ; + size_t i = n ; + char ch = c ; s += n ; while (i--) if (*--s == ch) return i ; return n ; diff --git a/src/libstddjb/case_lowerb.c b/src/libstddjb/case_lowerb.c index 9f51ed5..1285b52 100644 --- a/src/libstddjb/case_lowerb.c +++ b/src/libstddjb/case_lowerb.c @@ -1,10 +1,11 @@ /* ISC license. */ +#include <sys/types.h> #include <skalibs/bytestr.h> -void case_lowerb (register char *s, unsigned int len) +void case_lowerb (register char *s, size_t len) { - register unsigned char const d = 'a' - 'A' ; + unsigned char const d = 'a' - 'A' ; while (len--) { if (('A' <= *s) && (*s <= 'Z')) *s += d ; diff --git a/src/libstddjb/case_startb.c b/src/libstddjb/case_startb.c index cae0fb4..d69f461 100644 --- a/src/libstddjb/case_startb.c +++ b/src/libstddjb/case_startb.c @@ -1,9 +1,11 @@ /* ISC license. */ +#include <sys/types.h> +#include <string.h> #include <skalibs/bytestr.h> -int case_startb (register char const *s, unsigned int slen, register char const *t) +int case_startb (register char const *s, size_t slen, register char const *t) { - register unsigned int tlen = str_len(t) ; + size_t tlen = strlen(t) ; return slen < tlen ? 0 : !case_diffb(s, tlen, t) ; } diff --git a/src/libstddjb/case_str.c b/src/libstddjb/case_str.c index 14409c3..a6cd9b4 100644 --- a/src/libstddjb/case_str.c +++ b/src/libstddjb/case_str.c @@ -1,32 +1,33 @@ /* ISC license. */ -#include <skalibs/config.h> #include <skalibs/sysdeps.h> -#if defined(SKALIBS_HASSTRCASESTR) && !defined(SKALIBS_FLAG_REPLACE_LIBC) +#ifdef SKALIBS_HASSTRCASESTR #include <skalibs/nonposix.h> #include <string.h> #include <skalibs/bytestr.h> -unsigned int case_str (char const *haystack, char const *needle) +size_t case_str (char const *haystack, char const *needle) { register char *p = strcasestr(haystack, needle) ; - return p ? p - haystack : str_len(haystack) ; + return p ? p - haystack : strlen(haystack) ; } #else +#include <sys/types.h> +#include <string.h> #include <skalibs/bytestr.h> -unsigned int case_str (char const *haystack, char const *needle) +size_t case_str (char const *haystack, char const *needle) { - unsigned int nlen = str_len(needle) ; - register char const *p = haystack ; + size_t nlen = strlen(needle) ; + char const *p = haystack ; if (!nlen) return 0 ; for (; *p ; p++) if (!case_diffb(p, nlen, needle)) return p - haystack ; - return str_len(haystack) ; + return strlen(haystack) ; } #endif diff --git a/src/libstddjb/case_upperb.c b/src/libstddjb/case_upperb.c index 54ceab4..78ece8f 100644 --- a/src/libstddjb/case_upperb.c +++ b/src/libstddjb/case_upperb.c @@ -2,9 +2,9 @@ #include <skalibs/bytestr.h> -void case_upperb (register char *s, unsigned int len) +void case_upperb (char *s, size_t len) { - register unsigned char const d = 'a' - 'A' ; + unsigned char const d = 'a' - 'A' ; while (len--) { if (('a' <= *s) && (*s <= 'z')) *s -= d ; diff --git a/src/libstddjb/cdb_make.c b/src/libstddjb/cdb_make.c index 203d24c..c7e79d3 100644 --- a/src/libstddjb/cdb_make.c +++ b/src/libstddjb/cdb_make.c @@ -15,7 +15,7 @@ int cdb_make_start (struct cdb_make *c, int fd) { c->hplist = genalloc_zero ; c->pos = 2048 ; - buffer_init(&c->b, &fd_writesv, fd, c->buf, BUFFER_OUTSIZE) ; + buffer_init(&c->b, &fd_writev, fd, c->buf, BUFFER_OUTSIZE) ; return (int)lseek(fd, c->pos, SEEK_SET) ; } diff --git a/src/libstddjb/fd_cat.c b/src/libstddjb/fd_cat.c index 5682f02..1853427 100644 --- a/src/libstddjb/fd_cat.c +++ b/src/libstddjb/fd_cat.c @@ -1,16 +1,17 @@ /* ISC license. */ +#include <sys/types.h> #include <skalibs/iobuffer.h> #include <skalibs/djbunix.h> int fd_cat (int from, int to) { iobuffer b ; - unsigned int n = 0 ; + size_t n = 0 ; if (!iobuffer_init(&b, from, to)) return -1 ; for (;;) { - register int r = iobuffer_fill(&b) ; + register ssize_t r = iobuffer_fill(&b) ; if (r < 0) goto err ; else if (!r) break ; if (!iobuffer_flush(&b)) goto err ; diff --git a/src/libstddjb/fd_catn.c b/src/libstddjb/fd_catn.c index ca78546..b757853 100644 --- a/src/libstddjb/fd_catn.c +++ b/src/libstddjb/fd_catn.c @@ -1,20 +1,21 @@ /* ISC license. */ +#include <sys/types.h> #include <errno.h> #include <skalibs/allreadwrite.h> #include <skalibs/iobuffer.h> #include <skalibs/djbunix.h> -unsigned int fd_catn (int from, int to, unsigned int n) +size_t fd_catn (int from, int to, size_t n) { - unsigned int w = 0 ; + size_t w = 0 ; if (n >= IOBUFFER_SIZE) { iobuffer b ; if (!iobuffer_init(&b, from, to)) return 0 ; while (n >= IOBUFFER_SIZE) { - register int r = iobuffer_fill(&b) ; + register ssize_t r = iobuffer_fill(&b) ; if (r <= 0) { iobuffer_finish(&b) ; @@ -33,8 +34,8 @@ unsigned int fd_catn (int from, int to, unsigned int n) { char buf[n] ; - unsigned int r = allread(from, buf, n) ; - unsigned int v = 0 ; + size_t r = allread(from, buf, n) ; + size_t v = 0 ; if (r) v = allwrite(to, buf, r) ; w += v ; } diff --git a/src/libstddjb/fd_chown.c b/src/libstddjb/fd_chown.c index 8aa36c8..f4915ae 100644 --- a/src/libstddjb/fd_chown.c +++ b/src/libstddjb/fd_chown.c @@ -5,11 +5,11 @@ #include <errno.h> #include <skalibs/djbunix.h> -int fd_chown (int fd, unsigned int uid, unsigned int gid) +int fd_chown (int fd, uid_t uid, gid_t gid) { register int r ; do - r = fchown(fd, (uid_t)uid, (gid_t)gid) ; + r = fchown(fd, uid, gid) ; while ((r == -1) && (errno == EINTR)) ; return r ; } diff --git a/src/libstddjb/fd_copy2.c b/src/libstddjb/fd_copy2.c index 5537329..4f2e80d 100644 --- a/src/libstddjb/fd_copy2.c +++ b/src/libstddjb/fd_copy2.c @@ -1,6 +1,5 @@ /* ISC license. */ -#include <unistd.h> #include <errno.h> #include <skalibs/djbunix.h> diff --git a/src/libstddjb/fd_read.c b/src/libstddjb/fd_read.c index 22a296b..9664024 100644 --- a/src/libstddjb/fd_read.c +++ b/src/libstddjb/fd_read.c @@ -1,12 +1,13 @@ /* ISC license. */ +#include <sys/types.h> #include <unistd.h> #include <errno.h> #include <skalibs/allreadwrite.h> -int fd_read (int fd, char *buf, unsigned int len) +ssize_t fd_read (int fd, char *buf, size_t len) { - register int r ; + register ssize_t r ; do r = read(fd, buf, len) ; while ((r == -1) && (errno == EINTR)) ; return r ; diff --git a/src/libstddjb/fd_readsv.c b/src/libstddjb/fd_readsv.c deleted file mode 100644 index e4390df..0000000 --- a/src/libstddjb/fd_readsv.c +++ /dev/null @@ -1,13 +0,0 @@ -/* ISC license. */ - -#include <sys/types.h> -#include <sys/uio.h> -#include <skalibs/allreadwrite.h> -#include <skalibs/siovec.h> - -int fd_readsv (int fd, siovec_t const *v, unsigned int vlen) -{ - struct iovec vv[vlen] ; - iovec_from_siovec(vv, v, vlen) ; - return fd_readv(fd, vv, vlen) ; -} diff --git a/src/libstddjb/fd_readv.c b/src/libstddjb/fd_readv.c index c97d7ab..11dda66 100644 --- a/src/libstddjb/fd_readv.c +++ b/src/libstddjb/fd_readv.c @@ -5,9 +5,9 @@ #include <errno.h> #include <skalibs/allreadwrite.h> -int fd_readv (int fd, struct iovec const *v, unsigned int vlen) +ssize_t fd_readv (int fd, struct iovec const *v, unsigned int vlen) { - register int r ; + ssize_t r ; do r = readv(fd, v, vlen) ; while ((r == -1) && (errno == EINTR)) ; return r ; diff --git a/src/libstddjb/fd_recv.c b/src/libstddjb/fd_recv.c index 592dc8e..4eb8659 100644 --- a/src/libstddjb/fd_recv.c +++ b/src/libstddjb/fd_recv.c @@ -5,9 +5,9 @@ #include <errno.h> #include <skalibs/allreadwrite.h> -int fd_recv (int fd, char *buf, unsigned int len, unsigned int flags) +ssize_t fd_recv (int fd, char *buf, size_t len, unsigned int flags) { - register int r ; + register ssize_t r ; do r = recv(fd, buf, len, (int)flags) ; while ((r == -1) && (errno == EINTR)) ; return r ; diff --git a/src/libstddjb/fd_send.c b/src/libstddjb/fd_send.c index cdc3dd2..1d37bd5 100644 --- a/src/libstddjb/fd_send.c +++ b/src/libstddjb/fd_send.c @@ -5,9 +5,9 @@ #include <errno.h> #include <skalibs/allreadwrite.h> -int fd_send (int fd, char const *buf, unsigned int len, unsigned int flags) +ssize_t fd_send (int fd, char const *buf, size_t len, unsigned int flags) { - register int r ; + register ssize_t r ; do r = send(fd, buf, len, (int)flags) ; while ((r == -1) && (errno == EINTR)) ; return r ; diff --git a/src/libstddjb/fd_write.c b/src/libstddjb/fd_write.c index 636bce9..c6758fb 100644 --- a/src/libstddjb/fd_write.c +++ b/src/libstddjb/fd_write.c @@ -1,12 +1,13 @@ /* ISC license. */ +#include <sys/types.h> #include <unistd.h> #include <errno.h> #include <skalibs/allreadwrite.h> -int fd_write (int fd, char const *buf, unsigned int len) +ssize_t fd_write (int fd, char const *buf, size_t len) { - register int r ; + register ssize_t r ; do r = write(fd, buf, len) ; while ((r == -1) && (errno == EINTR)) ; return r ; diff --git a/src/libstddjb/fd_writesv.c b/src/libstddjb/fd_writesv.c deleted file mode 100644 index d16991b..0000000 --- a/src/libstddjb/fd_writesv.c +++ /dev/null @@ -1,13 +0,0 @@ -/* ISC license. */ - -#include <sys/types.h> -#include <sys/uio.h> -#include <skalibs/allreadwrite.h> -#include <skalibs/siovec.h> - -int fd_writesv (int fd, siovec_t const *v, unsigned int vlen) -{ - struct iovec vv[vlen] ; - iovec_from_siovec(vv, v, vlen) ; - return fd_writev(fd, vv, vlen) ; -} diff --git a/src/libstddjb/fd_writev.c b/src/libstddjb/fd_writev.c index d48d7f1..c54a20e 100644 --- a/src/libstddjb/fd_writev.c +++ b/src/libstddjb/fd_writev.c @@ -5,9 +5,9 @@ #include <errno.h> #include <skalibs/allreadwrite.h> -int fd_writev (int fd, struct iovec const *v, unsigned int vlen) +ssize_t fd_writev (int fd, struct iovec const *v, unsigned int vlen) { - register int r ; + register ssize_t r ; do r = writev(fd, v, vlen) ; while ((r == -1) && (errno == EINTR)) ; return r ; diff --git a/src/libstddjb/genalloc_deepfree.c b/src/libstddjb/genalloc_deepfree.c index cda800a..29f1527 100644 --- a/src/libstddjb/genalloc_deepfree.c +++ b/src/libstddjb/genalloc_deepfree.c @@ -1,12 +1,13 @@ /* ISC license. */ +#include <sys/types.h> #include <skalibs/stralloc.h> #include <skalibs/genalloc.h> -void genalloc_deepfree_size (genalloc *g, freefunc_t_ref f, unsigned int size) +void genalloc_deepfree_size (genalloc *g, freefunc_t_ref f, size_t size) { - unsigned int len = g->len / size ; - register unsigned int i = 0 ; + size_t len = g->len / size ; + register size_t i = 0 ; for (; i < len ; i++) (*f)(g->s + i * size) ; stralloc_free(g) ; } diff --git a/src/libstddjb/genwrite_put_bufalloc.c b/src/libstddjb/genwrite_put_bufalloc.c index 6aabe1c..4b5830d 100644 --- a/src/libstddjb/genwrite_put_bufalloc.c +++ b/src/libstddjb/genwrite_put_bufalloc.c @@ -1,10 +1,11 @@ /* ISC license. */ +#include <sys/types.h> #include <skalibs/bufalloc.h> #include <skalibs/genwrite.h> -int genwrite_put_bufalloc (void *target, char const *s, unsigned int len) +ssize_t genwrite_put_bufalloc (void *target, char const *s, size_t len) { register bufalloc *ba = target ; - return bufalloc_put(ba, s, len) ? (int)len : -1 ; + return bufalloc_put(ba, s, len) ? (ssize_t)len : -1 ; } diff --git a/src/libstddjb/genwrite_put_buffer.c b/src/libstddjb/genwrite_put_buffer.c index 1c85725..e5d7843 100644 --- a/src/libstddjb/genwrite_put_buffer.c +++ b/src/libstddjb/genwrite_put_buffer.c @@ -1,9 +1,10 @@ /* ISC license. */ +#include <sys/types.h> #include <skalibs/buffer.h> #include <skalibs/genwrite.h> -int genwrite_put_buffer (void *target, char const *s, unsigned int len) +ssize_t genwrite_put_buffer (void *target, char const *s, size_t len) { register buffer *b = target ; return buffer_put(b, s, len) ; diff --git a/src/libstddjb/genwrite_put_stralloc.c b/src/libstddjb/genwrite_put_stralloc.c index 2a8a8e8..6f1e2b7 100644 --- a/src/libstddjb/genwrite_put_stralloc.c +++ b/src/libstddjb/genwrite_put_stralloc.c @@ -1,10 +1,11 @@ /* ISC license. */ +#include <sys/types.h> #include <skalibs/stralloc.h> #include <skalibs/genwrite.h> -int genwrite_put_stralloc (void *target, char const *s, unsigned int len) +ssize_t genwrite_put_stralloc (void *target, char const *s, size_t len) { register stralloc *sa = target ; - return stralloc_catb(sa, s, len) ? (int)len : -1 ; + return stralloc_catb(sa, s, len) ? (ssize_t)len : -1 ; } diff --git a/src/libstddjb/iobufferu_init.c b/src/libstddjb/iobufferu_init.c index 490ac59..b9d643b 100644 --- a/src/libstddjb/iobufferu_init.c +++ b/src/libstddjb/iobufferu_init.c @@ -10,7 +10,7 @@ int iobufferu_init (iobufferu *b, int fdin, int fdout) register char *x = alloc(IOBUFFERU_SIZE) ; if (!x) return 0 ; b->buf = x ; - buffer_init(&b->b[0], &fd_readsv, fdin, x, IOBUFFERU_SIZE) ; - buffer_init(&b->b[1], &fd_writesv, fdout, x, IOBUFFERU_SIZE) ; + buffer_init(&b->b[0], &fd_readv, fdin, x, IOBUFFERU_SIZE) ; + buffer_init(&b->b[1], &fd_writev, fdout, x, IOBUFFERU_SIZE) ; return 1 ; } diff --git a/src/libstddjb/sanitize_read.c b/src/libstddjb/sanitize_read.c index bd8eee3..136f7ee 100644 --- a/src/libstddjb/sanitize_read.c +++ b/src/libstddjb/sanitize_read.c @@ -1,10 +1,11 @@ /* ISC license. */ +#include <sys/types.h> #include <errno.h> #include <skalibs/allreadwrite.h> #include <skalibs/error.h> -int sanitize_read (int r) +ssize_t sanitize_read (ssize_t r) { return r == -1 ? error_isagain(errno) ? (errno = 0, 0) : -1 : !r ? (errno = EPIPE, -1) : r ; diff --git a/src/libstddjb/str_chr.c b/src/libstddjb/str_chr.c index ed55e50..a415de6 100644 --- a/src/libstddjb/str_chr.c +++ b/src/libstddjb/str_chr.c @@ -1,33 +1,11 @@ /* ISC license. */ -#include <skalibs/config.h> -#include <skalibs/bytestr.h> - -#ifndef SKALIBS_FLAG_REPLACE_LIBC - +#include <sys/types.h> #include <string.h> +#include <skalibs/bytestr.h> -unsigned int str_chr (register char const *s, int c) -{ - register char *p = strchr(s, c) ; - return p ? (unsigned int)(p - s) : strlen(s) ; -} - -#else - -unsigned int str_chr (register char const *s, int c) +size_t str_chr (char const *s, int c) { - register char ch = c ; - register char const *t = s ; - - for (;;) - { - if (!*t) break; if (*t == ch) break; ++t; - if (!*t) break; if (*t == ch) break; ++t; - if (!*t) break; if (*t == ch) break; ++t; - if (!*t) break; if (*t == ch) break; ++t; - } - return t - s ; + char *p = strchr(s, c) ; + return p ? p - s : strlen(s) ; } - -#endif diff --git a/src/libstddjb/str_rchr.c b/src/libstddjb/str_rchr.c index 39a4822..c82ee69 100644 --- a/src/libstddjb/str_rchr.c +++ b/src/libstddjb/str_rchr.c @@ -1,28 +1,12 @@ /* ISC license. */ -#include <skalibs/config.h> -#include <skalibs/bytestr.h> - -#ifndef SKALIBS_FLAG_REPLACE_LIBC - +#include <sys/types.h> #include <string.h> +#include <skalibs/bytestr.h> -unsigned int str_rchr (register char const *s, int c) +size_t str_rchr (register char const *s, int c) { register char *p = strrchr(s, c) ; - return p ? (unsigned int)(p - s) : (unsigned int)strlen(s) ; -} - -#else - -unsigned int str_rchr (register char const *s, int c) -{ - register char ch = c ; - register char const *t = s ; - register char const *u = 0 ; - for ( ; *t ; t++) if (*t == ch) u = t ; - if (!u) u = t ; - return u - s ; + return p ? p - s : strlen(s) ; } -#endif diff --git a/src/libstddjb/str_strn.c b/src/libstddjb/str_strn.c index 7c2e425..fef219b 100644 --- a/src/libstddjb/str_strn.c +++ b/src/libstddjb/str_strn.c @@ -1,36 +1,16 @@ /* ISC license. */ -#include <skalibs/config.h> -#include <skalibs/bytestr.h> - -#ifdef SKALIBS_FLAG_REPLACE_LIBC - -/* Very naive implementation, but it's small. */ - -unsigned int str_strn (char const *haystack, unsigned int hlen, char const *needle, unsigned int nlen) -{ - register unsigned int i = 0 ; - if (!nlen) return 0 ; - if (hlen < nlen) return hlen ; - hlen -= nlen ; - for (; i <= hlen ; i++) - if (!byte_diff(haystack+i, nlen, needle)) return i ; - return hlen+nlen ; -} - -#else - +#include <sys/types.h> #include <string.h> +#include <skalibs/bytestr.h> -unsigned int str_strn (char const *haystack, unsigned int hlen, char const *needle, unsigned int nlen) +size_t str_strn (char const *haystack, size_t hlen, char const *needle, size_t nlen) { char haystack2[hlen+1] ; char needle2[nlen+1] ; - register char *p ; + char *p ; byte_copy(haystack2, hlen, haystack) ; haystack2[hlen] = 0 ; byte_copy(needle2, nlen, needle) ; needle2[nlen] = 0 ; p = strstr(haystack2, needle2) ; return p ? p - haystack2 : hlen ; } - -#endif diff --git a/src/libstddjb/stralloc_catb.c b/src/libstddjb/stralloc_catb.c index bb03405..f1bdc0a 100644 --- a/src/libstddjb/stralloc_catb.c +++ b/src/libstddjb/stralloc_catb.c @@ -1,12 +1,13 @@ /* ISC license. */ -#include <skalibs/bytestr.h> +#include <sys/types.h> +#include <string.h> #include <skalibs/stralloc.h> -int stralloc_catb (stralloc *sa, char const *s, unsigned int n) +int stralloc_catb (stralloc *sa, char const *s, size_t n) { if (!stralloc_readyplus(sa, n)) return 0 ; - byte_copy(sa->s + sa->len, n, s) ; + memmove(sa->s + sa->len, s, n) ; sa->len += n ; return 1 ; } diff --git a/src/libstddjb/stralloc_catv.c b/src/libstddjb/stralloc_catv.c index 1649f4c..684829c 100644 --- a/src/libstddjb/stralloc_catv.c +++ b/src/libstddjb/stralloc_catv.c @@ -1,21 +1,22 @@ /* ISC license. */ -#include <skalibs/bytestr.h> -#include <skalibs/siovec.h> +#include <sys/types.h> +#include <string.h> +#include <sys/uio.h> #include <skalibs/stralloc.h> -int stralloc_catv (stralloc *sa, siovec_t const *v, unsigned int n) +int stralloc_catv (stralloc *sa, struct iovec const *v, unsigned int n) { register unsigned int i = 0 ; { - unsigned int total = 0 ; - for (; i < n ; i++) total += v[i].len ; + 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++) { - byte_copy(sa->s + sa->len, v[i].len, v[i].s) ; - sa->len += v[i].len ; + memmove(sa->s + sa->len, v[i].iov_base, v[i].iov_len) ; + sa->len += v[i].iov_len ; } return 1 ; } diff --git a/src/libstddjb/stralloc_copyb.c b/src/libstddjb/stralloc_copyb.c index be2b397..31fc31e 100644 --- a/src/libstddjb/stralloc_copyb.c +++ b/src/libstddjb/stralloc_copyb.c @@ -1,12 +1,13 @@ /* ISC license. */ -#include <skalibs/bytestr.h> +#include <sys/types.h> +#include <string.h> #include <skalibs/stralloc.h> -int stralloc_copyb (stralloc *sa, char const *s, unsigned int n) +int stralloc_copyb (stralloc *sa, char const *s, size_t n) { if (!stralloc_ready(sa, n)) return 0 ; - byte_copy(sa->s, n, s) ; + memmove(sa->s, s, n) ; sa->len = n ; return 1 ; } diff --git a/src/libstddjb/stralloc_insertb.c b/src/libstddjb/stralloc_insertb.c index 339ffff..f964ea5 100644 --- a/src/libstddjb/stralloc_insertb.c +++ b/src/libstddjb/stralloc_insertb.c @@ -1,15 +1,15 @@ /* ISC license. */ +#include <sys/types.h> #include <errno.h> -#include <skalibs/bytestr.h> #include <skalibs/stralloc.h> -int stralloc_insertb (stralloc *sa, unsigned int offset, char const *s, unsigned int n) +int stralloc_insertb (stralloc *sa, size_t offset, char const *s, size_t n) { if (offset > sa->len) return (errno = EINVAL, 0) ; if (!stralloc_readyplus(sa, n)) return 0 ; - byte_copyr(sa->s + offset + n, sa->len - offset, sa->s + offset) ; + memmove(sa->s + offset + n, sa->s + offset, sa->len - offset) ; sa->len += n ; - byte_copyr(sa->s + offset, n, s) ; + memmove(sa->s + offset, s, n) ; return 1 ; } diff --git a/src/libstddjb/stralloc_ready_tuned.c b/src/libstddjb/stralloc_ready_tuned.c index 04e1a41..53a47cd 100644 --- a/src/libstddjb/stralloc_ready_tuned.c +++ b/src/libstddjb/stralloc_ready_tuned.c @@ -1,12 +1,13 @@ /* ISC license. */ +#include <sys/types.h> #include <errno.h> #include <skalibs/alloc.h> #include <skalibs/stralloc.h> -int stralloc_ready_tuned (stralloc *sa, unsigned int n, unsigned int base, unsigned int a, unsigned int b) +int stralloc_ready_tuned (stralloc *sa, size_t n, size_t base, size_t a, size_t b) { - register unsigned int t ; + register size_t t ; if (!b) return (errno = EINVAL, 0) ; t = n + base + a * n / b ; if (t < n) return (errno = ERANGE, 0) ; diff --git a/src/libstddjb/stralloc_reverse.c b/src/libstddjb/stralloc_reverse.c index 9ad29e7..46d22cb 100644 --- a/src/libstddjb/stralloc_reverse.c +++ b/src/libstddjb/stralloc_reverse.c @@ -1,11 +1,11 @@ /* ISC license. */ -#include <skalibs/bytestr.h> +#include <sys/types.h> #include <skalibs/stralloc.h> void stralloc_reverse (stralloc *sa) { - register unsigned int i = 0 ; + register size_t i = 0 ; for (; i < sa->len >> 1 ; i++) { char tmp = sa->s[i] ; diff --git a/src/libstddjb/stralloc_reverse_blocks.c b/src/libstddjb/stralloc_reverse_blocks.c index 6a2e4b8..67a18de 100644 --- a/src/libstddjb/stralloc_reverse_blocks.c +++ b/src/libstddjb/stralloc_reverse_blocks.c @@ -1,17 +1,18 @@ /* ISC license. */ -#include <skalibs/bytestr.h> +#include <sys/types.h> +#include <string.h> #include <skalibs/stralloc.h> -void stralloc_reverse_blocks (stralloc *sa, unsigned int size) +void stralloc_reverse_blocks (stralloc *sa, size_t size) { - register unsigned int n = sa->len / (size << 1) ; - register unsigned int i = 0 ; + register size_t n = sa->len / (size << 1) ; + register size_t i = 0 ; char tmp[size] ; for (; i < n ; i++) { - byte_copy(tmp, size, sa->s + i * size) ; - byte_copy(sa->s + i * size, size, sa->s + (2*n - 1 - i) * size) ; - byte_copy(sa->s + (2*n - 1 - i) * size, size, tmp) ; + memcpy(tmp, sa->s + i * size, size) ; + memcpy(sa->s + i * size, sa->s + (2*n - 1 - i) * size, size) ; + memcpy(sa->s + (2*n - 1 - i) * size, tmp, size) ; } } diff --git a/src/libstddjb/unsanitize_read.c b/src/libstddjb/unsanitize_read.c index efea22a..4d9e99d 100644 --- a/src/libstddjb/unsanitize_read.c +++ b/src/libstddjb/unsanitize_read.c @@ -1,10 +1,11 @@ /* ISC license. */ +#include <sys/types.h> #include <errno.h> #include <skalibs/allreadwrite.h> #include <skalibs/error.h> -int unsanitize_read (int r) +ssize_t unsanitize_read (ssize_t r) { return r == -1 ? errno == EPIPE ? (errno = 0, 0) : -1 : !r ? (errno = EWOULDBLOCK, -1) : r ; |