From 3534b428629be185e096be99e3bd5fdfe32d5544 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Thu, 18 Sep 2014 18:55:44 +0000 Subject: initial commit with rc for skalibs-2.0.0.0 --- src/libstddjb/netstring_decode.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/libstddjb/netstring_decode.c (limited to 'src/libstddjb/netstring_decode.c') diff --git a/src/libstddjb/netstring_decode.c b/src/libstddjb/netstring_decode.c new file mode 100644 index 0000000..a81756b --- /dev/null +++ b/src/libstddjb/netstring_decode.c @@ -0,0 +1,22 @@ +/* ISC license. */ + +#include +#include +#include +#include +#include + +int netstring_decode (stralloc *sa, char const *s, unsigned int len) +{ + unsigned int nlen ; + register unsigned int pos ; + if (!len) return 0 ; + pos = uint_scan(s, &nlen) ; + if (pos >= len) return (errno = EINVAL, -1) ; + if (s[pos] != ':') return (errno = EINVAL, -1) ; + s += pos+1 ; len -= pos+1 ; + if (len <= nlen) return (errno = EINVAL, -1) ; + if (s[nlen] != ',') return (errno = EINVAL, -1) ; + if (!stralloc_catb(sa, s, nlen)) return -1 ; + return pos + nlen + 2 ; +} -- cgit v1.3.1