summaryrefslogtreecommitdiff
path: root/src/libstddjb/buffer_putvall.c
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2015-02-05 23:56:14 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2015-02-05 23:56:14 +0000
commit153a646667ff5ae7578a6027938524db91c40821 (patch)
tree429f092f8254acbb207302d9dd8c790bc596322f /src/libstddjb/buffer_putvall.c
parentcea441e894405c6d28e302ae4360e9f848b37797 (diff)
downloadskalibs-153a646667ff5ae7578a6027938524db91c40821.tar.xz
- Add siovec_trunc
- Add openwritevnclose - replace buffer_read/write with fd_readsv/writesv - add localtmn_from_tain_g - refactor cdb_make - rewrite buffer_getvall and buffer_putvall, with a bugfix
Diffstat (limited to 'src/libstddjb/buffer_putvall.c')
-rw-r--r--src/libstddjb/buffer_putvall.c23
1 files changed, 16 insertions, 7 deletions
diff --git a/src/libstddjb/buffer_putvall.c b/src/libstddjb/buffer_putvall.c
index d6297c1..22b7ae4 100644
--- a/src/libstddjb/buffer_putvall.c
+++ b/src/libstddjb/buffer_putvall.c
@@ -2,14 +2,23 @@
#include <errno.h>
#include <skalibs/buffer.h>
-#include <skalibs/diuint.h>
#include <skalibs/siovec.h>
-int buffer_putvall (buffer *b, siovec_t const *v, unsigned int n, diuint *w)
+int buffer_putvall (buffer *b, siovec_t const *v, unsigned int n, unsigned int *written)
{
- if (w->left > n || (w->left == n && w->right) || w->right >= v[w->left].len)
- return (errno = EINVAL, 0) ;
- for (; w->left < n ; w->left++, w->right = 0)
- if (!buffer_putall(b, v[w->left].s, v[w->left].len, &w->right)) return 0 ;
- return 1 ;
+ unsigned int len = siovec_len(v, n) ;
+ unsigned int w = n ;
+ siovec_t vv[n] ;
+ if (*written > len) return (errno = EINVAL, 0) ;
+ while (w--) vv[w] = v[w] ;
+ w = *written ;
+ for (;;)
+ {
+ siovec_seek(vv, n, w) ;
+ w = buffer_putvnoflush(b, vv, n) ;
+ *written += w ;
+ if (*written >= len) return 1 ;
+ buffer_flush(b) ;
+ if (buffer_isfull(b)) return 0 ;
+ }
}