summaryrefslogtreecommitdiff
path: root/src/libstddjb/buffer_getvall.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_getvall.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_getvall.c')
-rw-r--r--src/libstddjb/buffer_getvall.c24
1 files changed, 18 insertions, 6 deletions
diff --git a/src/libstddjb/buffer_getvall.c b/src/libstddjb/buffer_getvall.c
index b6eeb46..e34c547 100644
--- a/src/libstddjb/buffer_getvall.c
+++ b/src/libstddjb/buffer_getvall.c
@@ -1,18 +1,30 @@
/* ISC license. */
#include <errno.h>
+#include <skalibs/allreadwrite.h>
#include <skalibs/buffer.h>
-#include <skalibs/diuint.h>
#include <skalibs/siovec.h>
-int buffer_getvall (buffer *b, siovec_t const *v, unsigned int n, diuint *w)
+int buffer_getvall (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, -1) ;
- for (; w->left < n ; w->left++, w->right = 0)
+ unsigned int len = siovec_len(v, n) ;
+ siovec_t vv[n] ;
+ if (*written > len) return (errno = EINVAL, -1) ;
{
- register int r = buffer_getall(b, v[w->left].s, v[w->left].len, &w->right) ;
+ register unsigned int i = n ;
+ while (i--) vv[i] = v[i] ;
+ }
+ siovec_seek(vv, n, *written) ;
+ for (;;)
+ {
+ register int r ;
+ unsigned int w = buffer_getvnofill(b, vv, n) ;
+ *written += w ;
+ if (*written >= len) break ;
+ siovec_seek(vv, n, w) ;
+ r = sanitize_read(buffer_fill(b)) ;
if (r <= 0) return r ;
}
return 1 ;
}
+