diff options
Diffstat (limited to 'src/libstddjb/siovec_trunc.c')
-rw-r--r-- | src/libstddjb/siovec_trunc.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/libstddjb/siovec_trunc.c b/src/libstddjb/siovec_trunc.c new file mode 100644 index 0000000..c09225a --- /dev/null +++ b/src/libstddjb/siovec_trunc.c @@ -0,0 +1,18 @@ +/* ISC license. */ + +#include <skalibs/bytestr.h> +#include <skalibs/siovec.h> + +unsigned int siovec_trunc (siovec_t *v, unsigned int n, unsigned int len) +{ + register unsigned int i = siovec_len(v, n) ; + if (i < len) return n ; + len = i - len ; + i = n ; + while (len && i--) + { + register unsigned int w = len > v[i].len ? v[i].len : len ; + v[i].len -= w ; len -= w ; + } + return i ; +} |