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/netstring_get.c | |
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/netstring_get.c')
-rw-r--r-- | src/libstddjb/netstring_get.c | 25 |
1 files changed, 13 insertions, 12 deletions
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 ; |