skalibs

Mirror/fork of https://skarnet.org/software/skalibs/
git clone https://ccx.te2000.cz/git/skalibs
Log | Files | Refs | README | LICENSE

buffer_flush.c (366B)


      1 /* ISC license. */
      2 
      3 #include <sys/uio.h>
      4 #include <skalibs/cbuffer.h>
      5 #include <skalibs/buffer.h>
      6 
      7 int buffer_flush (buffer *b)
      8 {
      9   for (;;)
     10   {
     11     struct iovec v[2] ;
     12     ssize_t r ;
     13     buffer_rpeek(b, v) ;
     14     if (!v[0].iov_len && !v[1].iov_len) break ;
     15     r = (*b->op)(b->fd, v, 2) ;
     16     if (r <= 0) return 0 ;
     17     cbuffer_RSEEK(&b->c, r) ;
     18   }
     19   return 1 ;
     20 }