summaryrefslogtreecommitdiff
path: root/src/libstddjb/buffer_flush.c
blob: 46512fc3e580f87ad3479cb0b169de2f764e094b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/* ISC license. */

#include <skalibs/cbuffer.h>
#include <skalibs/siovec.h>
#include <skalibs/buffer.h>

int buffer_flush (buffer *b)
{
  for (;;)
  {
    siovec_t v[2] ;
    register int r ;
    buffer_rpeek(b, v) ;
    if (!v[0].len && !v[1].len) break ;
    r = (*b->op)(b->fd, v, 2) ;
    if (r <= 0) return 0 ;
    cbuffer_RSEEK(&b->c, r) ;
  }
  return 1 ;
}