diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2017-01-25 15:52:18 +0000 |
---|---|---|
committer | Laurent Bercot <ska-skaware@skarnet.org> | 2017-01-25 15:52:18 +0000 |
commit | 00c9cb1b22cc17c4db573e0e613a5f116ff0092e (patch) | |
tree | 53178b2c52c6e97c6193f73378f3c5e5a781a914 /src/libstddjb | |
parent | 2746b131aa482ac17c94bc6b82e58dbcc1b752cf (diff) | |
download | skalibs-00c9cb1b22cc17c4db573e0e613a5f116ff0092e.tar.xz |
More work on the types. This commit builds but has errors.
Rework src/headers entirely: build skalibs/types.h
Convert skalibs/fmtscan.h types.
Propagate changes until it builds.
There are a lot of incompatible pointer issues remaining, those will be fixed with the buffer overhaul.
Diffstat (limited to 'src/libstddjb')
80 files changed, 409 insertions, 212 deletions
diff --git a/src/libstddjb/child_spawn.c b/src/libstddjb/child_spawn.c index 2170a6e..78b45ac 100644 --- a/src/libstddjb/child_spawn.c +++ b/src/libstddjb/child_spawn.c @@ -10,11 +10,11 @@ #include <unistd.h> #include <errno.h> #include <signal.h> +#include <skalibs/types.h> #include <skalibs/allreadwrite.h> #include <skalibs/bytestr.h> #include <skalibs/env.h> #include <skalibs/djbunix.h> -#include <skalibs/uint.h> #ifdef SKALIBS_HASPOSIXSPAWN diff --git a/src/libstddjb/fmtscan-internal.h b/src/libstddjb/fmtscan-internal.h index b1cac3e..3c9f214 100644 --- a/src/libstddjb/fmtscan-internal.h +++ b/src/libstddjb/fmtscan-internal.h @@ -3,17 +3,19 @@ #ifndef FMTSCAN_INTERNAL_H #define FMTSCAN_INTERNAL_H +#include <sys/types.h> +#include <stdint.h> #include <errno.h> #include <limits.h> #include <skalibs/bytestr.h> #include <skalibs/fmtscan.h> #define SCANB(bits) \ -unsigned int uint##bits##_scan_base (char const *s, uint##bits *u, unsigned char base) \ +size_t uint##bits##_scan_base (char const *s, uint##bits##_t *u, unsigned int base) \ { \ - static uint##bits const max = (uint##bits)(-1) ; \ - uint##bits result = 0 ; \ - unsigned int pos = 0 ; \ + static uint##bits##_t const max = UINT##bits##_MAX ; \ + uint##bits##_t result = 0 ; \ + size_t pos = 0 ; \ for (;; pos++) \ { \ register unsigned char c = fmtscan_num(s[pos], base) ; \ @@ -25,42 +27,42 @@ unsigned int uint##bits##_scan_base (char const *s, uint##bits *u, unsigned char } \ #define SCANB0(bits) \ -unsigned int uint##bits##0_scan_base (char const *s, uint##bits *u, unsigned char base) \ +size_t uint##bits##0_scan_base (char const *s, uint##bits##_t *u, unsigned int base) \ { \ - register unsigned int pos = uint##bits##_scan_base(s, u, base) ; \ + register size_t pos = uint##bits##_scan_base(s, u, base) ; \ if (!pos) return (errno = EINVAL, 0) ; \ if (!s[pos]) return pos ; \ errno = (fmtscan_num(s[pos], base) < base) ? EDOM : EINVAL ; \ return 0 ; \ } \ -#define SCANS(type, cstname) \ -unsigned int type##_scan (char const *s, type *n) \ +#define SCANS(bits) \ +size_t int##bits##_scan (char const *s, int##bits##_t *n) \ { \ - unsigned type tmp ; \ - register unsigned int r = 0 ; \ + uint##bits##_t tmp ; \ + register size_t r = 0 ; \ register unsigned int sign = 0 ; \ if (*s == '-') \ { \ - r = 1 + u##type##_scan(s+1, &tmp) ; \ + r = 1 + uint##bits##_scan(s+1, &tmp) ; \ if (r == 1) return 0 ; \ if (tmp == 0) *n = 0 ; \ else \ { \ - if (tmp-1 > -(cstname##_MIN+1)) \ + if (tmp-1 > -(INT##bits##_MIN+1)) \ { \ tmp /= 10 ; \ r-- ; \ } \ - *n = cstname##_MIN + (-(cstname##_MIN+1) - (tmp-1)) ; \ + *n = INT##bits##_MIN + (-(INT##bits##_MIN+1) - (tmp-1)) ; \ } \ return r ; \ } \ if (*s == '+') (s++, sign++) ; \ - r = u##type##_scan(s, &tmp) ; \ + r = uint##bits##_scan(s, &tmp) ; \ if (!r) return 0 ; \ r += sign ; \ - if (tmp > cstname##_MAX) \ + if (tmp > INT##bits##_MAX) \ { \ tmp /= 10 ; \ r-- ; \ @@ -69,13 +71,38 @@ unsigned int type##_scan (char const *s, type *n) \ return r ; \ } \ +#define SCANS0(bits) \ +size_t int##bits##0_scan (char const *s, int##bits##_t *u) \ +{ \ + register size_t pos = int##bits##_scan(s, u) ; \ + if (!pos) return (errno = EINVAL, 0) ; \ + if (!s[pos]) return pos ; \ + errno = (fmtscan_num(s[pos], 10) < 10) ? EDOM : EINVAL ; \ + return 0 ; \ +} \ + #define SCANL(bits) \ -unsigned int uint##bits##_scanlist (uint##bits *tab, unsigned int max, char const *s, unsigned int *num) \ +size_t uint##bits##_scanlist (uint##bits##_t *tab, size_t max, char const *s, size_t *num) \ +{ \ + size_t i = 0, len = 0 ; \ + for (; s[len] && (i < max) ; i++) \ + { \ + register size_t w = uint##bits##_scan(s + len, tab + i) ; \ + if (!w) break ; \ + len += w ; \ + while (byte_chr(",:; \t\r\n", 7, s[len]) < 7) len++ ; \ + } \ + *num = i ; \ + return len ; \ +} \ + +#define SCANSL(bits) \ +size_t int##bits##_scanlist (int##bits##_t *tab, size_t max, char const *s, size_t *num) \ { \ - unsigned int i = 0, len = 0 ; \ + size_t i = 0, len = 0 ; \ for (; s[len] && (i < max) ; i++) \ { \ - register unsigned int w = uint##bits##_scan(s + len, tab + i) ; \ + register size_t w = int##bits##_scan(s + len, tab + i) ; \ if (!w) break ; \ len += w ; \ while (byte_chr(",:; \t\r\n", 7, s[len]) < 7) len++ ; \ @@ -85,12 +112,12 @@ unsigned int uint##bits##_scanlist (uint##bits *tab, unsigned int max, char cons } \ #define FMTL(bits) \ -unsigned int uint##bits##_fmtlist (char *s, uint##bits const *tab, unsigned int n) \ +size_t uint##bits##_fmtlist (char *s, uint##bits##_t const *tab, size_t n) \ { \ - unsigned int i = 0, len = 0 ; \ + size_t i = 0, len = 0 ; \ for (; i < n ; i++) \ { \ - register unsigned int w = uint##bits##_fmt(s, tab[i]) ; \ + register size_t w = uint##bits##_fmt(s, tab[i]) ; \ len += w ; \ if (s) \ { \ @@ -101,5 +128,53 @@ unsigned int uint##bits##_fmtlist (char *s, uint##bits const *tab, unsigned int return len ; \ } \ +#define FMTB(bits) \ +size_t uint##bits##_fmt_base (char *s, uint##bits##_t x, unsigned int base) \ +{ \ + register size_t len = 1 ; \ + { \ + register uint##bits##_t q = x ; \ + while (q >= base) { len++ ; q /= base ; } \ + } \ + if (s) \ + { \ + s += len ; \ + do { *--s = fmtscan_asc(x % base) ; x /= base ; } while (x) ; \ + } \ + return len ; \ +} \ + +#define FMTB0(bits) \ +size_t uint##bits##0_fmt_base (char *s, uint##bits##_t x, register size_t n, unsigned int base) \ +{ \ + register size_t len = uint##bits##_fmt_base(0, x, base) ; \ + while (n-- > len) *s++ = '0' ; \ + return uint##bits##_fmt_base(s, x, base) ; \ +} \ + +#define FMTS(bits) \ +size_t int##bits##_fmt (char *fmt, int##bits##_t n) \ +{ \ + if (n >= 0) return uint##bits##_fmt(fmt, n) ; \ + if (fmt) *fmt++ = '-' ; \ + return 1 + uint##bits##_fmt(fmt, -n) ; \ +} \ + +#define FMTSL(bits) \ +size_t int##bits##_fmtlist (char *s, int##bits##_t const *tab, size_t n) \ +{ \ + size_t i = 0, len = 0 ; \ + for (; i < n ; i++) \ + { \ + register size_t w = int##bits##_fmt(s, tab[i]) ; \ + len += w ; \ + if (s) \ + { \ + s += w ; \ + if (i < n-1) { *s++ = ',' ; len++ ; } \ + } \ + } \ + return len ; \ +} \ #endif diff --git a/src/libstddjb/int_scan.c b/src/libstddjb/int160_scan.c index 2547a04..f2ce735 100644 --- a/src/libstddjb/int_scan.c +++ b/src/libstddjb/int160_scan.c @@ -1,6 +1,6 @@ /* ISC license. */ -#include <skalibs/uint.h> #include "fmtscan-internal.h" +#include <skalibs/uint16.h> -SCANS(int, INT) +SCANS0(16) diff --git a/src/libstddjb/long_scan.c b/src/libstddjb/int16_fmt.c index 34a5e1a..6dff58b 100644 --- a/src/libstddjb/long_scan.c +++ b/src/libstddjb/int16_fmt.c @@ -1,6 +1,6 @@ /* ISC license. */ -#include <skalibs/ulong.h> #include "fmtscan-internal.h" +#include <skalibs/uint16.h> -SCANS(long, LONG) +FMTS(16) diff --git a/src/libstddjb/short_scan.c b/src/libstddjb/int16_fmtlist.c index 898ba9f..4ec6899 100644 --- a/src/libstddjb/short_scan.c +++ b/src/libstddjb/int16_fmtlist.c @@ -1,6 +1,6 @@ /* ISC license. */ -#include <skalibs/ushort.h> #include "fmtscan-internal.h" +#include <skalibs/uint16.h> -SCANS(short, SHRT) +FMTSL(16) diff --git a/src/libstddjb/int16_scan.c b/src/libstddjb/int16_scan.c new file mode 100644 index 0000000..b20523d --- /dev/null +++ b/src/libstddjb/int16_scan.c @@ -0,0 +1,6 @@ +/* ISC license. */ + +#include "fmtscan-internal.h" +#include <skalibs/uint16.h> + +SCANS(16) diff --git a/src/libstddjb/int16_scanlist.c b/src/libstddjb/int16_scanlist.c new file mode 100644 index 0000000..9b4bf87 --- /dev/null +++ b/src/libstddjb/int16_scanlist.c @@ -0,0 +1,6 @@ +/* ISC license. */ + +#include "fmtscan-internal.h" +#include <skalibs/uint16.h> + +SCANSL(16) diff --git a/src/libstddjb/int320_scan.c b/src/libstddjb/int320_scan.c new file mode 100644 index 0000000..dea7c91 --- /dev/null +++ b/src/libstddjb/int320_scan.c @@ -0,0 +1,6 @@ +/* ISC license. */ + +#include "fmtscan-internal.h" +#include <skalibs/uint32.h> + +SCANS0(32) diff --git a/src/libstddjb/int32_fmt.c b/src/libstddjb/int32_fmt.c new file mode 100644 index 0000000..dc0ff1b --- /dev/null +++ b/src/libstddjb/int32_fmt.c @@ -0,0 +1,6 @@ +/* ISC license. */ + +#include "fmtscan-internal.h" +#include <skalibs/uint32.h> + +FMTS(32) diff --git a/src/libstddjb/int32_fmtlist.c b/src/libstddjb/int32_fmtlist.c new file mode 100644 index 0000000..aac8d33 --- /dev/null +++ b/src/libstddjb/int32_fmtlist.c @@ -0,0 +1,6 @@ +/* ISC license. */ + +#include "fmtscan-internal.h" +#include <skalibs/uint32.h> + +FMTSL(32) diff --git a/src/libstddjb/int32_scan.c b/src/libstddjb/int32_scan.c new file mode 100644 index 0000000..ba4510a --- /dev/null +++ b/src/libstddjb/int32_scan.c @@ -0,0 +1,6 @@ +/* ISC license. */ + +#include "fmtscan-internal.h" +#include <skalibs/uint32.h> + +SCANS(32) diff --git a/src/libstddjb/int32_scanlist.c b/src/libstddjb/int32_scanlist.c new file mode 100644 index 0000000..b9e92d0 --- /dev/null +++ b/src/libstddjb/int32_scanlist.c @@ -0,0 +1,6 @@ +/* ISC license. */ + +#include "fmtscan-internal.h" +#include <skalibs/uint32.h> + +SCANSL(32) diff --git a/src/libstddjb/int640_scan.c b/src/libstddjb/int640_scan.c new file mode 100644 index 0000000..69e9f6d --- /dev/null +++ b/src/libstddjb/int640_scan.c @@ -0,0 +1,6 @@ +/* ISC license. */ + +#include "fmtscan-internal.h" +#include <skalibs/uint64.h> + +SCANS0(64) diff --git a/src/libstddjb/int64_fmt.c b/src/libstddjb/int64_fmt.c new file mode 100644 index 0000000..d2b7145 --- /dev/null +++ b/src/libstddjb/int64_fmt.c @@ -0,0 +1,6 @@ +/* ISC license. */ + +#include "fmtscan-internal.h" +#include <skalibs/uint64.h> + +FMTS(64) diff --git a/src/libstddjb/int64_fmtlist.c b/src/libstddjb/int64_fmtlist.c new file mode 100644 index 0000000..8027708 --- /dev/null +++ b/src/libstddjb/int64_fmtlist.c @@ -0,0 +1,6 @@ +/* ISC license. */ + +#include "fmtscan-internal.h" +#include <skalibs/uint64.h> + +FMTSL(64) diff --git a/src/libstddjb/int64_scan.c b/src/libstddjb/int64_scan.c new file mode 100644 index 0000000..934e84c --- /dev/null +++ b/src/libstddjb/int64_scan.c @@ -0,0 +1,6 @@ +/* ISC license. */ + +#include "fmtscan-internal.h" +#include <skalibs/uint64.h> + +SCANS(64) diff --git a/src/libstddjb/int64_scanlist.c b/src/libstddjb/int64_scanlist.c new file mode 100644 index 0000000..6a121a8 --- /dev/null +++ b/src/libstddjb/int64_scanlist.c @@ -0,0 +1,6 @@ +/* ISC license. */ + +#include "fmtscan-internal.h" +#include <skalibs/uint64.h> + +SCANSL(64) diff --git a/src/libstddjb/ip46_scan.c b/src/libstddjb/ip46_scan.c index 97ebe4d..73045e6 100644 --- a/src/libstddjb/ip46_scan.c +++ b/src/libstddjb/ip46_scan.c @@ -1,13 +1,12 @@ /* ISC license. */ -#include <skalibs/ip46.h> - +#include <sys/types.h> #include <skalibs/fmtscan.h> #include <skalibs/ip46.h> -unsigned int ip46full_scan (char const *s, ip46full_t_ref ip) +size_t ip46full_scan (char const *s, ip46full_t *ip) { - unsigned int len = ip6_scan(s, ip->ip) ; + size_t len = ip6_scan(s, ip->ip) ; if (len) ip->is6 = 1 ; else { diff --git a/src/libstddjb/ip46_scanlist.c b/src/libstddjb/ip46_scanlist.c index 6462da7..7ee2b68 100644 --- a/src/libstddjb/ip46_scanlist.c +++ b/src/libstddjb/ip46_scanlist.c @@ -1,17 +1,17 @@ /* ISC license. */ +#include <sys/types.h> #include <skalibs/ip46.h> - #include <skalibs/bytestr.h> #include <skalibs/fmtscan.h> -unsigned int ip46full_scanlist (ip46full_t *out, unsigned int max, char const *s, unsigned int *num) +size_t ip46full_scanlist (ip46full_t *out, size_t max, char const *s, size_t *num) { - unsigned int n = 0, w = 0 ; + size_t n = 0, w = 0 ; for (; s[w] && (n < max) ; n++) { ip46full_t z ; - register unsigned int i = ip6_scan(s + w, z.ip) ; + register size_t i = ip6_scan(s + w, z.ip) ; if (i) z.is6 = 1 ; else { diff --git a/src/libstddjb/ip4_fmt.c b/src/libstddjb/ip4_fmt.c index 4c2f6a3..9804b38 100644 --- a/src/libstddjb/ip4_fmt.c +++ b/src/libstddjb/ip4_fmt.c @@ -1,15 +1,16 @@ /* ISC license. */ +#include <sys/types.h> #include <skalibs/uint32.h> #include <skalibs/fmtscan.h> -unsigned int ip4_fmt (char *s, char const *ip) +size_t ip4_fmt (char *s, char const *ip) { - unsigned int len = 0 ; - unsigned int i, j ; - for (j = 0 ; j < 4 ; j++) + size_t len = 0 ; + unsigned int j = 0 ; + for (; j < 4 ; j++) { - i = uint32_fmt(s, (uint32)(unsigned char) ip[j]) ; + size_t i = uint32_fmt(s, (unsigned char)ip[j]) ; len += i ; if (s) s += i ; if (j == 3) break ; diff --git a/src/libstddjb/ip4_fmtu32.c b/src/libstddjb/ip4_fmtu32.c index d4833e8..9347cef 100644 --- a/src/libstddjb/ip4_fmtu32.c +++ b/src/libstddjb/ip4_fmtu32.c @@ -1,9 +1,11 @@ /* ISC license. */ +#include <sys/types.h> +#include <stdint.h> #include <skalibs/uint32.h> #include <skalibs/fmtscan.h> -unsigned int ip4_fmtu32 (char *s, uint32 ip) +size_t ip4_fmtu32 (char *s, uint32_t ip) { char pack[4] ; uint32_pack_big(pack, ip) ; diff --git a/src/libstddjb/ip4_scan.c b/src/libstddjb/ip4_scan.c index 2873cd4..749a176 100644 --- a/src/libstddjb/ip4_scan.c +++ b/src/libstddjb/ip4_scan.c @@ -1,15 +1,16 @@ /* ISC license. */ -#include <skalibs/uint.h> +#include <skalibs/types.h> +#include <skalibs/fmtscan.h> -unsigned int ip4_scan (char const *s, char *ip) +size_t ip4_scan (char const *s, char *ip) { + size_t len = 0 ; register unsigned int j = 0 ; - unsigned int len = 0 ; for (; j < 4 ; j++) { unsigned int u ; - register unsigned int i = uint_scan(s, &u) ; + register size_t i = uint_scan(s, &u) ; if (!i) return 0 ; ip[j] = (char)u ; s += i ; diff --git a/src/libstddjb/ip4_scanlist.c b/src/libstddjb/ip4_scanlist.c index f1e3ccc..edc2949 100644 --- a/src/libstddjb/ip4_scanlist.c +++ b/src/libstddjb/ip4_scanlist.c @@ -1,14 +1,15 @@ /* ISC license. */ +#include <sys/types.h> #include <skalibs/bytestr.h> #include <skalibs/fmtscan.h> -unsigned int ip4_scanlist (char *out, unsigned int max, char const *s, unsigned int *num) +size_t ip4_scanlist (char *out, size_t max, char const *s, size_t *num) { - unsigned int n = 0, w = 0 ; + size_t n = 0, w = 0 ; for (; s[w] && (n < max) ; n++) { - register unsigned int i = ip4_scan(s + w, out + (n << 2)) ; + register size_t i = ip4_scan(s + w, out + (n << 2)) ; if (!i) break ; w += i ; while (byte_chr(",:; \t\r\n", 7, s[w]) < 7) w++ ; diff --git a/src/libstddjb/ip4_scanlist_u32.c b/src/libstddjb/ip4_scanlist_u32.c index 26a4e38..10c24cf 100644 --- a/src/libstddjb/ip4_scanlist_u32.c +++ b/src/libstddjb/ip4_scanlist_u32.c @@ -1,15 +1,17 @@ /* ISC license. */ +#include <sys/types.h> +#include <stdint.h> #include <skalibs/uint32.h> #include <skalibs/bytestr.h> #include <skalibs/fmtscan.h> -unsigned int ip4_scanlist_u32 (uint32 *out, unsigned int max, char const *s, unsigned int *num) +size_t ip4_scanlist_u32 (uint32_t *out, size_t max, char const *s, size_t *num) { - unsigned int n = 0, w = 0 ; + size_t n = 0, w = 0 ; for (; s[w] && (n < max) ; n++) { - register unsigned int i = ip4_scanu32(s + w, out + n) ; + register size_t i = ip4_scanu32(s + w, out + n) ; if (!i) break ; w += i ; while (byte_chr(",:; \t\r\n", 7, s[w]) < 7) w++ ; diff --git a/src/libstddjb/ip4_scanu32.c b/src/libstddjb/ip4_scanu32.c index a305926..205c52d 100644 --- a/src/libstddjb/ip4_scanu32.c +++ b/src/libstddjb/ip4_scanu32.c @@ -1,12 +1,14 @@ /* ISC license. */ +#include <sys/types.h> +#include <stdint.h> #include <skalibs/uint32.h> #include <skalibs/fmtscan.h> -unsigned int ip4_scanu32 (char const *s, uint32 *ip) +size_t ip4_scanu32 (char const *s, uint32_t *ip) { char pack[4] ; - register unsigned int r = ip4_scan(s, pack) ; + register size_t r = ip4_scan(s, pack) ; if (r) uint32_unpack_big(pack, ip) ; return r ; } diff --git a/src/libstddjb/ip6_fmt.c b/src/libstddjb/ip6_fmt.c index afd8a21..eb6acc0 100644 --- a/src/libstddjb/ip6_fmt.c +++ b/src/libstddjb/ip6_fmt.c @@ -1,13 +1,14 @@ /* ISC license. */ +#include <sys/types.h> #include <skalibs/diuint.h> #include <skalibs/fmtscan.h> #define px(c) ((j || (c)) ? (*s++ = fmtscan_asc(c), 1) : 0) -static inline unsigned int xfmt16 (char *s, char const *key) +static inline size_t xfmt16 (char *s, char const *key) { - register unsigned int j = 0 ; + register 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) ; @@ -55,9 +56,9 @@ static inline unsigned int find_colcol (char const *key, unsigned int *pos) return 0 ; } -unsigned int ip6_fmt (char *s, char const *ip6) +size_t ip6_fmt (char *s, char const *ip6) { - unsigned int w = 0 ; + size_t w = 0 ; register unsigned int i = 0 ; unsigned int pos = 8 ; unsigned int len = find_colcol(ip6, &pos) ; diff --git a/src/libstddjb/ip6_scan.c b/src/libstddjb/ip6_scan.c index cb2dc49..1e34051 100644 --- a/src/libstddjb/ip6_scan.c +++ b/src/libstddjb/ip6_scan.c @@ -1,15 +1,18 @@ /* ISC license. */ +#include <sys/types.h> +#include <stdint.h> #include <errno.h> #include <skalibs/uint16.h> #include <skalibs/fmtscan.h> -unsigned int ip6_scan (char const *s, char *ip6) +size_t ip6_scan (char const *s, char *ip6) { static const unsigned char class[256] = "2222222222222222222222222222222222222222222222220000000000122222200000022222222222222222222222222000000222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222" ; static const unsigned char table[5][3] = { "\024#\005", "\024\"\005", "\024\005\006", "\005\002\005", "\024\t\016" } ; - uint16 tmp[8] = { 0, 0, 0, 0, 0, 0, 0, 0 } ; - unsigned int pos = 8, j = 0, state = 0, i = 0 ; + uint16_t tmp[8] = { 0, 0, 0, 0, 0, 0, 0, 0 } ; + size_t i = 0 ; + unsigned int pos = 8, j = 0, state = 0 ; while (state < 5) { diff --git a/src/libstddjb/ip6_scanlist.c b/src/libstddjb/ip6_scanlist.c index 8d751a6..cf1c7fd 100644 --- a/src/libstddjb/ip6_scanlist.c +++ b/src/libstddjb/ip6_scanlist.c @@ -1,15 +1,16 @@ /* ISC license. */ +#include <sys/types.h> #include <skalibs/bytestr.h> #include <skalibs/fmtscan.h> -unsigned int ip6_scanlist (char *out, unsigned int max, char const *s, unsigned int *num) +size_t ip6_scanlist (char *out, size_t max, char const *s, size_t *num) { - unsigned int n = 0, w = 0 ; + size_t n = 0, w = 0 ; for (; s[w] && (n < max) ; n++) { char ip[16] ; - register unsigned int i = ip6_scan(s + w, ip) ; + register size_t i = ip6_scan(s + w, ip) ; if (!i) break ; byte_copy(out + (n << 4), 16, ip) ; w += i ; diff --git a/src/libstddjb/localtm_fmt.c b/src/libstddjb/localtm_fmt.c index ee083ef..dc8095a 100644 --- a/src/libstddjb/localtm_fmt.c +++ b/src/libstddjb/localtm_fmt.c @@ -1,10 +1,11 @@ /* ISC license. */ +#include <sys/types.h> #include <time.h> -#include <skalibs/uint.h> +#include <skalibs/types.h> #include <skalibs/djbtime.h> -unsigned int localtm_fmt (char *s, struct tm const *l) +size_t localtm_fmt (char *s, struct tm const *l) { char *p = s ; p += uint_fmt(p, 1900 + l->tm_year) ; *p++ = '-' ; diff --git a/src/libstddjb/localtm_scan.c b/src/libstddjb/localtm_scan.c index b028883..62bf4c3 100644 --- a/src/libstddjb/localtm_scan.c +++ b/src/libstddjb/localtm_scan.c @@ -1,37 +1,52 @@ /* ISC license. */ +#include <sys/types.h> #include <errno.h> #include <time.h> +#include <skalibs/types.h> #include <skalibs/djbtime.h> -#include <skalibs/uint.h> -unsigned int localtm_scan (char const *s, struct tm *l) +size_t localtm_scan (char const *s, struct tm *l) { struct tm ll = { .tm_isdst = -1 } ; - unsigned int n = 0 ; unsigned int u ; - register unsigned int i = uint_scan(s+n, &u) ; - if (!i) goto fail ; n += i ; - if (u < 1900) goto fail ; u -= 1900 ; ll.tm_year = u ; + size_t n = 0 ; + unsigned int u ; + register size_t i = uint_scan(s+n, &u) ; + if (!i) goto fail ; + n += i ; + if (u < 1900) goto fail ; + u -= 1900 ; ll.tm_year = u ; if (s[n++] != '-') goto fail ; i = uint_scan(s+n, &u) ; - if (!i) goto fail ; n += i ; - if (!u || (u > 12)) goto fail ; u-- ; ll.tm_mon = u ; + if (!i) goto fail ; + n += i ; + if (!u || (u > 12)) goto fail ; + u-- ; ll.tm_mon = u ; if (s[n++] != '-') goto fail ; i = uint_scan(s+n, &u) ; - if (!i) goto fail ; n += i ; - if (!u || (u > 31)) goto fail ; ll.tm_mday = u ; - if ((s[n] != ' ') && (s[n] != 'T')) goto fail ; n++ ; + if (!i) goto fail ; + n += i ; + if (!u || (u > 31)) goto fail ; + ll.tm_mday = u ; + if ((s[n] != ' ') && (s[n] != 'T')) goto fail ; + n++ ; i = uint_scan(s+n, &u) ; - if (!i) goto fail ; n += i ; - if (u > 23) goto fail ; ll.tm_hour = u ; + if (!i) goto fail ; + n += i ; + if (u > 23) goto fail ; + ll.tm_hour = u ; if (s[n++] != ':') goto fail ; i = uint_scan(s+n, &u) ; - if (!i) goto fail ; n += i ; - if (u > 59) goto fail ; ll.tm_min = u ; + if (!i) goto fail ; + n += i ; + if (u > 59) goto fail ; + ll.tm_min = u ; if (s[n++] != ':') goto fail ; i = uint_scan(s+n, &u) ; - if (!i) goto fail ; n += i ; - if (u > 60) goto fail ; ll.tm_sec = u ; + if (!i) goto fail ; + n += i ; + if (u > 60) goto fail ; + ll.tm_sec = u ; if (mktime(&ll) == (time_t)-1) goto fail ; *l = ll ; return n ; diff --git a/src/libstddjb/localtmn_fmt.c b/src/libstddjb/localtmn_fmt.c index 79a869d..b47911d 100644 --- a/src/libstddjb/localtmn_fmt.c +++ b/src/libstddjb/localtmn_fmt.c @@ -1,9 +1,10 @@ /* ISC license. */ +#include <sys/types.h> #include <skalibs/uint32.h> #include <skalibs/djbtime.h> -unsigned int localtmn_fmt (char *s, localtmn_t const *l) +size_t localtmn_fmt (char *s, localtmn_t const *l) { char *p = s ; p += localtm_fmt(p, &l->tm) ; *p++ = '.' ; diff --git a/src/libstddjb/localtmn_scan.c b/src/libstddjb/localtmn_scan.c index fa5cbcd..c9d4d19 100644 --- a/src/libstddjb/localtmn_scan.c +++ b/src/libstddjb/localtmn_scan.c @@ -1,18 +1,19 @@ /* ISC license. */ +#include <sys/types.h> #include <skalibs/uint32.h> #include <skalibs/djbtime.h> -unsigned int localtmn_scan (char const *s, localtmn_t *l) +size_t localtmn_scan (char const *s, localtmn_t *l) { localtmn_t m ; - unsigned int n = localtm_scan(s, &m.tm) ; + size_t n = localtm_scan(s, &m.tm) ; if (!n) return 0 ; s += n ; if (*s++ != '.') m.nano = 0 ; else { - register unsigned int b = uint32_scan(s, &m.nano) ; + register size_t b = uint32_scan(s, &m.nano) ; if (!b) return 0 ; n += b ; } diff --git a/src/libstddjb/long_fmt.c b/src/libstddjb/long_fmt.c deleted file mode 100644 index 552fe47..0000000 --- a/src/libstddjb/long_fmt.c +++ /dev/null @@ -1,10 +0,0 @@ -/* ISC license. */ - -#include <skalibs/ulong.h> - -unsigned int long_fmt (char *fmt, long n) -{ - if (n >= 0) return ulong_fmt(fmt, n) ; - if (fmt) *fmt++ = '-' ; - return 1 + ulong_fmt(fmt, -n) ; -} diff --git a/src/libstddjb/netstring_append.c b/src/libstddjb/netstring_append.c index 9c14f49..88098a4 100644 --- a/src/libstddjb/netstring_append.c +++ b/src/libstddjb/netstring_append.c @@ -1,14 +1,15 @@ /* ISC license. */ -#include <skalibs/uint.h> +#include <sys/types.h> +#include <skalibs/uint64.h> #include <skalibs/bytestr.h> #include <skalibs/stralloc.h> #include <skalibs/netstring.h> -int netstring_appendb (stralloc *sa, char const *s, unsigned int len) +int netstring_appendb (stralloc *sa, char const *s, size_t len) { - char fmt[UINT_FMT] ; - unsigned int n = uint_fmt(fmt, len) ; + char fmt[UINT64_FMT] ; + size_t n = uint64_fmt(fmt, len) ; if (!stralloc_readyplus(sa, len + n + 2)) return 0 ; fmt[n] = ':' ; byte_copy(sa->s + sa->len, n+1, fmt) ; diff --git a/src/libstddjb/netstring_appendv.c b/src/libstddjb/netstring_appendv.c index 1fc1406..1d9c290 100644 --- a/src/libstddjb/netstring_appendv.c +++ b/src/libstddjb/netstring_appendv.c @@ -1,26 +1,27 @@ /* ISC license. */ -#include <skalibs/uint.h> +#include <sys/types.h> +#include <skalibs/uint64.h> #include <skalibs/bytestr.h> #include <skalibs/siovec.h> #include <skalibs/stralloc.h> #include <skalibs/netstring.h> -int netstring_appendv (stralloc *sa, siovec_t const *v, unsigned int n) +int netstring_appendv (stralloc *sa, struct iovec const *v, unsigned int n) { - char fmt[UINT_FMT] ; - unsigned int len = 0, pos ; + char fmt[UINT64_FMT] ; + size_t len = 0, pos ; register unsigned int i = 0 ; - for (; i < n ; i++) len += v[i].len ; - pos = uint_fmt(fmt, len) ; + for (; i < n ; i++) len += v[i].iov_len ; + pos = uint64_fmt(fmt, len) ; if (!stralloc_readyplus(sa, len + pos + 2)) return 0 ; fmt[pos] = ':' ; byte_copy(sa->s + sa->len, pos+1, fmt) ; sa->len += pos+1 ; for (i = 0 ; i < n ; i++) { - byte_copy(sa->s + sa->len, v[i].len, v[i].s) ; - sa->len += v[i].len ; + byte_copy(sa->s + sa->len, v[i].iov_len, (char const *)v[i].iov_base) ; + sa->len += v[i].iov_len ; } sa->s[sa->len++] = ',' ; return 1 ; diff --git a/src/libstddjb/netstring_decode.c b/src/libstddjb/netstring_decode.c index a81756b..d129ea8 100644 --- a/src/libstddjb/netstring_decode.c +++ b/src/libstddjb/netstring_decode.c @@ -1,17 +1,17 @@ /* ISC license. */ +#include <sys/types.h> #include <errno.h> -#include <skalibs/fmtscan.h> +#include <skalibs/uint64.h> #include <skalibs/netstring.h> #include <skalibs/stralloc.h> -#include <skalibs/uint.h> -int netstring_decode (stralloc *sa, char const *s, unsigned int len) +ssize_t netstring_decode (stralloc *sa, char const *s, size_t len) { - unsigned int nlen ; - register unsigned int pos ; + uint64_t nlen ; + register size_t pos ; if (!len) return 0 ; - pos = uint_scan(s, &nlen) ; + pos = uint64_scan(s, &nlen) ; if (pos >= len) return (errno = EINVAL, -1) ; if (s[pos] != ':') return (errno = EINVAL, -1) ; s += pos+1 ; len -= pos+1 ; diff --git a/src/libstddjb/netstring_encode.c b/src/libstddjb/netstring_encode.c index c13abd6..6b2d0ea 100644 --- a/src/libstddjb/netstring_encode.c +++ b/src/libstddjb/netstring_encode.c @@ -1,13 +1,14 @@ /* ISC license. */ +#include <sys/types.h> +#include <skalibs/uint64.h> #include <skalibs/netstring.h> #include <skalibs/stralloc.h> -#include <skalibs/uint.h> -int netstring_encode (stralloc *sa, char const *s, unsigned int len) +int netstring_encode (stralloc *sa, char const *s, size_t len) { - char fmt[UINT_FMT] ; - unsigned int pos = uint_fmt(fmt, len) ; + char fmt[UINT64_FMT] ; + size_t pos = uint64_fmt(fmt, len) ; if (!stralloc_readyplus(sa, pos + len + 2)) return 0 ; stralloc_catb(sa, fmt, pos) ; stralloc_catb(sa, ":", 1) ; diff --git a/src/libstddjb/netstring_get.c b/src/libstddjb/netstring_get.c index 6f6c602..c2f8b05 100644 --- a/src/libstddjb/netstring_get.c +++ b/src/libstddjb/netstring_get.c @@ -1,8 +1,9 @@ /* ISC license. */ +#include <sys/types.h> #include <errno.h> +#include <skalibs/uint64.h> #include <skalibs/allreadwrite.h> -#include <skalibs/uint.h> #include <skalibs/bytestr.h> #include <skalibs/buffer.h> #include <skalibs/cbuffer.h> @@ -10,25 +11,25 @@ #include <skalibs/stralloc.h> #include <skalibs/netstring.h> -int netstring_okeof (buffer *b, unsigned int w) +int netstring_okeof (buffer *b, size_t w) { return (errno == EPIPE) && !w && buffer_isempty(b) ? (errno = 0, 1) : 0 ; } -int netstring_get (buffer *b, stralloc *sa, unsigned int *state) +ssize_t netstring_get (buffer *b, stralloc *sa, size_t *state) { if (!*state) { - unsigned int n ; - unsigned int len ; - char buf[UINT_FMT] ; - if (b->c.a < UINT_FMT+1) return (errno = EINVAL, -1) ; + size_t n ; + size_t len ; + char buf[UINT64_FMT] ; + if (b->c.a < UINT64_FMT+1) return (errno = EINVAL, -1) ; for (;;) { register int r ; - len = buffer_getnofill(b, buf, UINT_FMT) ; + len = buffer_getnofill(b, buf, UINT64_FMT) ; n = byte_chr(buf, len, ':') ; /* XXX: accepts :, as a valid netstring */ - if (n >= UINT_FMT) + if (n >= UINT64_FMT) { buffer_unget(b, len) ; return (errno = EPROTO, -1) ; @@ -39,13 +40,13 @@ int netstring_get (buffer *b, stralloc *sa, unsigned int *state) if (r <= 0) return r ; } buffer_unget(b, len - n - 1) ; - if (!n || n != uint_scan(buf, &len)) return (errno = EPROTO, -1) ; + if (!n || n != uint64_scan(buf, &len)) return (errno = EPROTO, -1) ; if (!stralloc_readyplus(sa, len + 1)) return -1 ; *state = len + 1 ; } { - unsigned int w = 0 ; - register int r = buffer_getall(b, sa->s + sa->len, *state, &w) ; + size_t w = 0 ; + register ssize_t 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/netstring_put.c b/src/libstddjb/netstring_put.c index 5a27b25..692d2fc 100644 --- a/src/libstddjb/netstring_put.c +++ b/src/libstddjb/netstring_put.c @@ -1,34 +1,35 @@ /* ISC license. */ +#include <sys/types.h> #include <errno.h> +#include <skalibs/uint64.h> #include <skalibs/buffer.h> #include <skalibs/netstring.h> -#include <skalibs/uint.h> -int netstring_put (buffer *b, char const *s, unsigned int len, unsigned int *written) +int netstring_put (buffer *b, char const *s, size_t len, size_t *written) { - char fmt[UINT_FMT] ; - unsigned int n = uint_fmt(fmt, len) ; + char fmt[UINT64_FMT] ; + size_t n = uint64_fmt(fmt, len) ; if (*written > len + n + 2) return (errno = EINVAL, 0) ; fmt[n] = ':' ; if (*written < n + 1) { - unsigned int w = *written ; - int r = buffer_putall(b, fmt, n+1, &w) ; + size_t w = *written ; + ssize_t r = buffer_putall(b, fmt, n+1, &w) ; if (r < 0) return (*written = w, 0) ; *written = n+1 ; } if (*written < n+1 + len) { - unsigned int w = *written - (n+1) ; - int r = buffer_putall(b, s, len, &w) ; + size_t w = *written - (n+1) ; + ssize_t r = buffer_putall(b, s, len, &w) ; *written = w + (n+1) ; if (r < 0) return (*written = n+1 + w, 0) ; *written = n+1 + len ; } { - unsigned int w = 0 ; - int r = buffer_putall(b, ",", 1, &w) ; + size_t w = 0 ; + ssize_t r = buffer_putall(b, ",", 1, &w) ; if (r < 0) return 0 ; } *written = 0 ; diff --git a/src/libstddjb/sauniquename.c b/src/libstddjb/sauniquename.c index ddf47ec..ff102fa 100644 --- a/src/libstddjb/sauniquename.c +++ b/src/libstddjb/sauniquename.c @@ -1,11 +1,11 @@ /* ISC license. */ #include <unistd.h> +#include <skalibs/types.h> #include <skalibs/djbunix.h> #include <skalibs/skamisc.h> #include <skalibs/stralloc.h> #include <skalibs/tai.h> -#include <skalibs/uint.h> int sauniquename (stralloc *sa) { @@ -17,7 +17,7 @@ int sauniquename (stralloc *sa) timestamp(sa->s + base + 1) ; sa->s[base + 1 + TIMESTAMP] = ':' ; sa->len = base + 2 + TIMESTAMP ; - sa->len += uint_fmt(sa->s + sa->len, getpid()) ; + sa->len += pid_fmt(sa->s + sa->len, getpid()) ; sa->s[sa->len++] = ':' ; if (sagethostname(sa) == -1) goto err ; return 1 ; diff --git a/src/libstddjb/str_fmt.c b/src/libstddjb/str_fmt.c index 1c14c70..220119a 100644 --- a/src/libstddjb/str_fmt.c +++ b/src/libstddjb/str_fmt.c @@ -1,9 +1,9 @@ /* ISC license. */ -#include <skalibs/bytestr.h> +#include <string.h> #include <skalibs/fmtscan.h> -unsigned int str_fmt (register char *d, char const *s) +size_t str_fmt (char *d, char const *s) { - return strn_fmt(d, s, str_len(s)) ; + return strn_fmt(d, s, strlen(s)) ; } diff --git a/src/libstddjb/strn_fmt.c b/src/libstddjb/strn_fmt.c index bbb9651..0c6ffb7 100644 --- a/src/libstddjb/strn_fmt.c +++ b/src/libstddjb/strn_fmt.c @@ -1,12 +1,13 @@ /* ISC license. */ +#include <sys/types.h> +#include <skalibs/types.h> #include <skalibs/fmtscan.h> -#include <skalibs/uint.h> -unsigned int strn_fmt (char *blah, register char const *s, unsigned int len) +size_t strn_fmt (char *blah, register char const *s, size_t len) { register char *d = blah ; - unsigned int i ; + size_t i ; for (i = 0 ; i < len ; i++) if ((s[i] >= 32) && ((unsigned char)s[i] < 127)) *d++ = s[i] ; else diff --git a/src/libstddjb/ucharn_findlen.c b/src/libstddjb/ucharn_findlen.c index 1016647..59b5577 100644 --- a/src/libstddjb/ucharn_findlen.c +++ b/src/libstddjb/ucharn_findlen.c @@ -1,10 +1,11 @@ /* ISC license. */ +#include <sys/types.h> #include <skalibs/fmtscan.h> -unsigned int ucharn_findlen (char const *s) +size_t ucharn_findlen (char const *s) { - register unsigned int i = 0 ; + register size_t i = 0 ; while (fmtscan_num(s[i], 16) <= 0xF) i++ ; return i ; } diff --git a/src/libstddjb/ucharn_fmt.c b/src/libstddjb/ucharn_fmt.c index 2943fdf..5eec54f 100644 --- a/src/libstddjb/ucharn_fmt.c +++ b/src/libstddjb/ucharn_fmt.c @@ -1,10 +1,11 @@ /* ISC license. */ +#include <sys/types.h> #include <skalibs/fmtscan.h> -unsigned int ucharn_fmt (char *s, char const *key, unsigned int n) +size_t ucharn_fmt (char *s, char const *key, size_t n) { - register unsigned int i = 0 ; + register size_t i = 0 ; for (; i < n ; i++) { s[i<<1] = fmtscan_asc((unsigned char)key[i] >> 4) ; diff --git a/src/libstddjb/ucharn_fmt_little.c b/src/libstddjb/ucharn_fmt_little.c index 8450c46..d033096 100644 --- a/src/libstddjb/ucharn_fmt_little.c +++ b/src/libstddjb/ucharn_fmt_little.c @@ -1,10 +1,11 @@ /* ISC license. */ +#include <sys/types.h> #include <skalibs/fmtscan.h> -unsigned int ucharn_fmt_little (char *s, char const *key, unsigned int n) +size_t ucharn_fmt_little (char *s, char const *key, size_t n) { - register unsigned int i = 0 ; + register size_t i = 0 ; for (; i < n ; i++) { s[i<<1] = fmtscan_asc((unsigned char)key[i] & 0xF) ; diff --git a/src/libstddjb/ucharn_scan.c b/src/libstddjb/ucharn_scan.c index cdcc403..b544d0d 100644 --- a/src/libstddjb/ucharn_scan.c +++ b/src/libstddjb/ucharn_scan.c @@ -1,8 +1,9 @@ /* ISC license. */ +#include <sys/types.h> #include <skalibs/fmtscan.h> -unsigned int ucharn_scan (char const *s, char *key, unsigned int n) +size_t ucharn_scan (char const *s, char *key, size_t n) { register unsigned int i = 0 ; for (; i < n ; i++) diff --git a/src/libstddjb/ucharn_scan_little.c b/src/libstddjb/ucharn_scan_little.c index 5b66af5..b278dff 100644 --- a/src/libstddjb/ucharn_scan_little.c +++ b/src/libstddjb/ucharn_scan_little.c @@ -1,10 +1,11 @@ /* ISC license. */ +#include <sys/types.h> #include <skalibs/fmtscan.h> -unsigned int ucharn_scan_little (char const *s, char *key, unsigned int n) +size_t ucharn_scan_little (char const *s, char *key, size_t n) { - register unsigned int i = 0 ; + register size_t i = 0 ; for (; i < n ; i++) { unsigned char c = fmtscan_num(s[(i<<1)+1], 16) ; diff --git a/src/libstddjb/uint160_fmt.c b/src/libstddjb/uint160_fmt.c new file mode 100644 index 0000000..ccd2485 --- /dev/null +++ b/src/libstddjb/uint160_fmt.c @@ -0,0 +1,6 @@ +/* ISC license. */ + +#include "fmtscan-internal.h" +#include <skalibs/uint16.h> + +FMTB0(16) diff --git a/src/libstddjb/uint160_scan.c b/src/libstddjb/uint160_scan.c index 9a48514..36d04f3 100644 --- a/src/libstddjb/uint160_scan.c +++ b/src/libstddjb/uint160_scan.c @@ -1,6 +1,6 @@ /* ISC license. */ -#include <skalibs/uint16.h> #include "fmtscan-internal.h" +#include <skalibs/uint16.h> SCANB0(16) diff --git a/src/libstddjb/uint16_fmt.c b/src/libstddjb/uint16_fmt.c new file mode 100644 index 0000000..668c2bf --- /dev/null +++ b/src/libstddjb/uint16_fmt.c @@ -0,0 +1,6 @@ +/* ISC license. */ + +#include "fmtscan-internal.h" +#include <skalibs/uint16.h> + +FMTB(16) diff --git a/src/libstddjb/uint16_fmtlist.c b/src/libstddjb/uint16_fmtlist.c index 721b443..4898d5c 100644 --- a/src/libstddjb/uint16_fmtlist.c +++ b/src/libstddjb/uint16_fmtlist.c @@ -1,6 +1,6 @@ /* ISC license. */ -#include <skalibs/uint16.h> #include "fmtscan-internal.h" +#include <skalibs/uint16.h> FMTL(16) diff --git a/src/libstddjb/uint16_pack.c b/src/libstddjb/uint16_pack.c index c84f504..56b5dcb 100644 --- a/src/libstddjb/uint16_pack.c +++ b/src/libstddjb/uint16_pack.c @@ -1,9 +1,10 @@ /* ISC license. */ +#include <stdint.h> #include <skalibs/uint16.h> #include <skalibs/bytestr.h> -void uint16_pack (char *s, uint16 u) +void uint16_pack (char *s, uint16_t u) { ((unsigned char *)s)[0] = T8(u) ; u >>= 8 ; ((unsigned char *)s)[1] = T8(u) ; diff --git a/src/libstddjb/uint16_pack_big.c b/src/libstddjb/uint16_pack_big.c index 9fac1fa..b5b0f01 100644 --- a/src/libstddjb/uint16_pack_big.c +++ b/src/libstddjb/uint16_pack_big.c @@ -1,9 +1,10 @@ /* ISC license. */ +#include <stdint.h> #include <skalibs/uint16.h> #include <skalibs/bytestr.h> -void uint16_pack_big (char *s, uint16 u) +void uint16_pack_big (char *s, uint16_t u) { ((unsigned char *)s)[1] = T8(u) ; u >>= 8 ; ((unsigned char *)s)[0] = T8(u) ; diff --git a/src/libstddjb/uint16_reverse.c b/src/libstddjb/uint16_reverse.c index fedade1..9a6e8d9 100644 --- a/src/libstddjb/uint16_reverse.c +++ b/src/libstddjb/uint16_reverse.c @@ -1,8 +1,9 @@ /* ISC license. */ +#include <sys/types.h> #include <skalibs/uint16.h> -void uint16_reverse (char *s, unsigned int n) +void uint16_reverse (char *s, size_t n) { while (n--) { diff --git a/src/libstddjb/uint16_scan.c b/src/libstddjb/uint16_scan.c index 5665807..4c0564e 100644 --- a/src/libstddjb/uint16_scan.c +++ b/src/libstddjb/uint16_scan.c @@ -1,6 +1,6 @@ /* ISC license. */ -#include <skalibs/uint16.h> #include "fmtscan-internal.h" +#include <skalibs/uint16.h> SCANB(16) diff --git a/src/libstddjb/uint16_scanlist.c b/src/libstddjb/uint16_scanlist.c index e98777f..afb9af4 100644 --- a/src/libstddjb/uint16_scanlist.c +++ b/src/libstddjb/uint16_scanlist.c @@ -1,6 +1,6 @@ /* ISC license. */ -#include <skalibs/uint16.h> #include "fmtscan-internal.h" +#include <skalibs/uint16.h> SCANL(16) diff --git a/src/libstddjb/uint16_unpack.c b/src/libstddjb/uint16_unpack.c index c3ade45..1497671 100644 --- a/src/libstddjb/uint16_unpack.c +++ b/src/libstddjb/uint16_unpack.c @@ -1,11 +1,12 @@ /* ISC license. */ +#include <stdint.h> #include <skalibs/uint16.h> #include <skalibs/bytestr.h> -void uint16_unpack (char const *s, uint16 *u) +void uint16_unpack (char const *s, uint16_t *u) { - uint16 r = T8((unsigned char)s[1]) ; r <<= 8 ; + uint16_t r = T8((unsigned char)s[1]) ; r <<= 8 ; r += T8((unsigned char)s[0]) ; *u = r ; } diff --git a/src/libstddjb/uint16_unpack_big.c b/src/libstddjb/uint16_unpack_big.c index 2f22555..73b94da 100644 --- a/src/libstddjb/uint16_unpack_big.c +++ b/src/libstddjb/uint16_unpack_big.c @@ -1,11 +1,12 @@ /* ISC license. */ +#include <stdint.h> #include <skalibs/uint16.h> #include <skalibs/bytestr.h> -void uint16_unpack_big (char const *s, uint16 *u) +void uint16_unpack_big (char const *s, uint16_t *u) { - uint16 r = T8((unsigned char)s[0]) ; r <<= 8 ; + uint16_t r = T8((unsigned char)s[0]) ; r <<= 8 ; r += T8((unsigned char)s[1]) ; *u = r ; } diff --git a/src/libstddjb/uint320_fmt.c b/src/libstddjb/uint320_fmt.c new file mode 100644 index 0000000..7de9833 --- /dev/null +++ b/src/libstddjb/uint320_fmt.c @@ -0,0 +1,6 @@ +/* ISC license. */ + +#include "fmtscan-internal.h" +#include <skalibs/uint32.h> + +FMTB0(32) diff --git a/src/libstddjb/uint320_scan.c b/src/libstddjb/uint320_scan.c index 103354c..2c63e65 100644 --- a/src/libstddjb/uint320_scan.c +++ b/src/libstddjb/uint320_scan.c @@ -1,6 +1,6 @@ /* ISC license. */ -#include <skalibs/uint32.h> #include "fmtscan-internal.h" +#include <skalibs/uint32.h> SCANB0(32) diff --git a/src/libstddjb/uint32_fmt.c b/src/libstddjb/uint32_fmt.c new file mode 100644 index 0000000..4364285 --- /dev/null +++ b/src/libstddjb/uint32_fmt.c @@ -0,0 +1,6 @@ +/* ISC license. */ + +#include "fmtscan-internal.h" +#include <skalibs/uint32.h> + +FMTB(32) diff --git a/src/libstddjb/uint32_fmtlist.c b/src/libstddjb/uint32_fmtlist.c index 831dcfc..d7e96be 100644 --- a/src/libstddjb/uint32_fmtlist.c +++ b/src/libstddjb/uint32_fmtlist.c @@ -1,6 +1,6 @@ /* ISC license. */ -#include <skalibs/uint32.h> #include "fmtscan-internal.h" +#include <skalibs/uint32.h> FMTL(32) diff --git a/src/libstddjb/uint32_pack.c b/src/libstddjb/uint32_pack.c index d467c3d..75febe0 100644 --- a/src/libstddjb/uint32_pack.c +++ b/src/libstddjb/uint32_pack.c @@ -1,9 +1,10 @@ /* ISC license. */ +#include <stdint.h> #include <skalibs/uint32.h> #include <skalibs/bytestr.h> -void uint32_pack (char *s, uint32 u) +void uint32_pack (char *s, uint32_t u) { ((unsigned char *)s)[0] = T8(u) ; u >>= 8 ; ((unsigned char *)s)[1] = T8(u) ; u >>= 8 ; diff --git a/src/libstddjb/uint32_pack_big.c b/src/libstddjb/uint32_pack_big.c index 487cf21..02f0eb6 100644 --- a/src/libstddjb/uint32_pack_big.c +++ b/src/libstddjb/uint32_pack_big.c @@ -1,9 +1,10 @@ /* ISC license. */ +#include <stdint.h> #include <skalibs/uint32.h> #include <skalibs/bytestr.h> -void uint32_pack_big (char *s, uint32 u) +void uint32_pack_big (char *s, uint32_t u) { ((unsigned char *)s)[3] = T8(u) ; u >>= 8 ; ((unsigned char *)s)[2] = T8(u) ; u >>= 8 ; diff --git a/src/libstddjb/uint32_reverse.c b/src/libstddjb/uint32_reverse.c index 18b3b43..6a33f23 100644 --- a/src/libstddjb/uint32_reverse.c +++ b/src/libstddjb/uint32_reverse.c @@ -1,8 +1,9 @@ /* ISC license. */ +#include <sys/types.h> #include <skalibs/uint32.h> -void uint32_reverse (char *s, unsigned int n) +void uint32_reverse (char *s, size_t n) { while (n--) { diff --git a/src/libstddjb/uint32_scan.c b/src/libstddjb/uint32_scan.c index 06e2d77..58d43e6 100644 --- a/src/libstddjb/uint32_scan.c +++ b/src/libstddjb/uint32_scan.c @@ -1,6 +1,6 @@ /* ISC license. */ -#include <skalibs/uint32.h> #include "fmtscan-internal.h" +#include <skalibs/uint32.h> SCANB(32) diff --git a/src/libstddjb/uint32_scanlist.c b/src/libstddjb/uint32_scanlist.c index 8af3ae9..34d8067 100644 --- a/src/libstddjb/uint32_scanlist.c +++ b/src/libstddjb/uint32_scanlist.c @@ -1,6 +1,6 @@ /* ISC license. */ -#include <skalibs/uint32.h> #include "fmtscan-internal.h" +#include <skalibs/uint32.h> SCANL(32) diff --git a/src/libstddjb/uint32_unpack.c b/src/libstddjb/uint32_unpack.c index d5dabcc..a9cabbb 100644 --- a/src/libstddjb/uint32_unpack.c +++ b/src/libstddjb/uint32_unpack.c @@ -1,11 +1,12 @@ /* ISC license. */ +#include <stdint.h> #include <skalibs/uint32.h> #include <skalibs/bytestr.h> -void uint32_unpack (char const *s, uint32 *u) +void uint32_unpack (char const *s, uint32_t *u) { - uint32 r = T8((unsigned char)s[3]) ; r <<= 8 ; + uint32_t r = T8((unsigned char)s[3]) ; r <<= 8 ; r += T8((unsigned char)s[2]) ; r <<= 8 ; r += T8((unsigned char)s[1]) ; r <<= 8 ; r += T8((unsigned char)s[0]) ; diff --git a/src/libstddjb/uint32_unpack_big.c b/src/libstddjb/uint32_unpack_big.c index 1a53292..defde56 100644 --- a/src/libstddjb/uint32_unpack_big.c +++ b/src/libstddjb/uint32_unpack_big.c @@ -1,11 +1,12 @@ /* ISC license. */ +#include <stdint.h> #include <skalibs/uint32.h> #include <skalibs/bytestr.h> -void uint32_unpack_big (char const *s, uint32 *u) +void uint32_unpack_big (char const *s, uint32_t *u) { - uint32 r = T8((unsigned char)s[0]) ; r <<= 8 ; + uint32_t r = T8((unsigned char)s[0]) ; r <<= 8 ; r += T8((unsigned char)s[1]) ; r <<= 8 ; r += T8((unsigned char)s[2]) ; r <<= 8 ; r += T8((unsigned char)s[3]) ; diff --git a/src/libstddjb/uint640_fmt.c b/src/libstddjb/uint640_fmt.c index 7153055..dc9cfa5 100644 --- a/src/libstddjb/uint640_fmt.c +++ b/src/libstddjb/uint640_fmt.c @@ -1,10 +1,6 @@ /* ISC license. */ +#include "fmtscan-internal.h" #include <skalibs/uint64.h> -unsigned int uint640_fmt_base (char *s, uint64 x, register unsigned int n, unsigned char base) -{ - register unsigned int len = uint64_fmt_base(0, x, base) ; - while (n-- > len) *s++ = '0' ; - return uint64_fmt_base(s, x, base) ; -} +FMTB0(64) diff --git a/src/libstddjb/uint640_scan.c b/src/libstddjb/uint640_scan.c index 45c8e20..28ae049 100644 --- a/src/libstddjb/uint640_scan.c +++ b/src/libstddjb/uint640_scan.c @@ -1,6 +1,6 @@ /* ISC license. */ -#include <skalibs/uint64.h> #include "fmtscan-internal.h" +#include <skalibs/uint64.h> SCANB0(64) diff --git a/src/libstddjb/uint64_fmt.c b/src/libstddjb/uint64_fmt.c index cbe3382..91c8178 100644 --- a/src/libstddjb/uint64_fmt.c +++ b/src/libstddjb/uint64_fmt.c @@ -1,19 +1,6 @@ /* ISC license. */ +#include "fmtscan-internal.h" #include <skalibs/uint64.h> -#include <skalibs/fmtscan.h> -unsigned int uint64_fmt_base (char *s, uint64 x, unsigned char base) -{ - register unsigned int len = 1 ; - { - register uint64 q = x ; - while (q >= base) { len++ ; q /= base ; } - } - if (s) - { - s += len ; - do { *--s = fmtscan_asc(x % base) ; x /= base ; } while (x) ; - } - return len ; -} +FMTB(64) diff --git a/src/libstddjb/uint64_fmtlist.c b/src/libstddjb/uint64_fmtlist.c index 7d9b321..5aa5e49 100644 --- a/src/libstddjb/uint64_fmtlist.c +++ b/src/libstddjb/uint64_fmtlist.c @@ -1,6 +1,6 @@ /* ISC license. */ -#include <skalibs/uint64.h> #include "fmtscan-internal.h" +#include <skalibs/uint64.h> FMTL(64) diff --git a/src/libstddjb/uint64_pack.c b/src/libstddjb/uint64_pack.c index 23c8e19..5559a90 100644 --- a/src/libstddjb/uint64_pack.c +++ b/src/libstddjb/uint64_pack.c @@ -3,7 +3,7 @@ #include <skalibs/uint64.h> #include <skalibs/bytestr.h> -void uint64_pack (char *s, uint64 u) +void uint64_pack (char *s, uint64_t u) { ((unsigned char *)s)[0] = T8(u) ; u >>= 8 ; ((unsigned char *)s)[1] = T8(u) ; u >>= 8 ; diff --git a/src/libstddjb/uint64_pack_big.c b/src/libstddjb/uint64_pack_big.c index 17d0206..381f105 100644 --- a/src/libstddjb/uint64_pack_big.c +++ b/src/libstddjb/uint64_pack_big.c @@ -3,7 +3,7 @@ #include <skalibs/uint64.h> #include <skalibs/bytestr.h> -void uint64_pack_big (char *s, uint64 u) +void uint64_pack_big (char *s, uint64_t u) { ((unsigned char *)s)[7] = T8(u) ; u >>= 8 ; ((unsigned char *)s)[6] = T8(u) ; u >>= 8 ; diff --git a/src/libstddjb/uint64_reverse.c b/src/libstddjb/uint64_reverse.c index f8730fe..29e81d1 100644 --- a/src/libstddjb/uint64_reverse.c +++ b/src/libstddjb/uint64_reverse.c @@ -1,8 +1,9 @@ /* ISC license. */ +#include <sys/types.h> #include <skalibs/uint64.h> -void uint64_reverse (char *s, unsigned int n) +void uint64_reverse (char *s, size_t n) { while (n--) { diff --git a/src/libstddjb/uint64_scan.c b/src/libstddjb/uint64_scan.c index 530e84c..33744b1 100644 --- a/src/libstddjb/uint64_scan.c +++ b/src/libstddjb/uint64_scan.c @@ -1,6 +1,6 @@ /* ISC license. */ -#include <skalibs/uint64.h> #include "fmtscan-internal.h" +#include <skalibs/uint64.h> SCANB(64) diff --git a/src/libstddjb/uint64_scanlist.c b/src/libstddjb/uint64_scanlist.c index 5ffeaa7..f288bcc 100644 --- a/src/libstddjb/uint64_scanlist.c +++ b/src/libstddjb/uint64_scanlist.c @@ -1,6 +1,6 @@ /* ISC license. */ -#include <skalibs/uint64.h> #include "fmtscan-internal.h" +#include <skalibs/uint64.h> SCANL(64) diff --git a/src/libstddjb/uint64_unpack.c b/src/libstddjb/uint64_unpack.c index e0561d9..452d3ea 100644 --- a/src/libstddjb/uint64_unpack.c +++ b/src/libstddjb/uint64_unpack.c @@ -3,9 +3,9 @@ #include <skalibs/uint64.h> #include <skalibs/bytestr.h> -void uint64_unpack (char const *s, uint64 *u) +void uint64_unpack (char const *s, uint64_t *u) { - uint64 r = T8((unsigned char)s[7]) ; r <<= 8 ; + uint64_t r = T8((unsigned char)s[7]) ; r <<= 8 ; r += T8((unsigned char)s[6]) ; r <<= 8 ; r += T8((unsigned char)s[5]) ; r <<= 8 ; r += T8((unsigned char)s[4]) ; r <<= 8 ; diff --git a/src/libstddjb/uint64_unpack_big.c b/src/libstddjb/uint64_unpack_big.c index ebb419b..3554dcc 100644 --- a/src/libstddjb/uint64_unpack_big.c +++ b/src/libstddjb/uint64_unpack_big.c @@ -3,9 +3,9 @@ #include <skalibs/uint64.h> #include <skalibs/bytestr.h> -void uint64_unpack_big (char const *s, uint64 *u) +void uint64_unpack_big (char const *s, uint64_t *u) { - uint64 r = T8((unsigned char)s[0]) ; r <<= 8 ; + uint64_t r = T8((unsigned char)s[0]) ; r <<= 8 ; r += T8((unsigned char)s[1]) ; r <<= 8 ; r += T8((unsigned char)s[2]) ; r <<= 8 ; r += T8((unsigned char)s[3]) ; r <<= 8 ; |