File: obuf_flush.c

package info (click to toggle)
bglibs 2.04%2Bdfsg-8
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,468 kB
  • sloc: ansic: 15,821; perl: 674; sh: 63; makefile: 29
file content (25 lines) | stat: -rw-r--r-- 587 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <errno.h>
#include <unistd.h>
#include "obuf.h"

/** Write all pending data in the \c obuf to the file descriptor. */
int obuf_flush(obuf* out)
{
  iobuf* io;
  unsigned wr;
  
  io = &out->io;
  if (iobuf_bad(io)) return 0;
  while (io->bufstart < io->buflen) {
    if (io->timeout && !iobuf_timeout(io, 1)) return 0;
    wr = out->writefn(io->fd, io->buffer+io->bufstart,
		      io->buflen-io->bufstart);
    if (wr == (unsigned)-1) IOBUF_SET_ERROR(io);
    io->bufstart += wr;
    io->offset += wr;
  }
  io->buflen = 0;
  io->bufstart = 0;
  out->bufpos = 0;
  return 1;
}