File: obuf_copyfromfd.c

package info (click to toggle)
bglibs 2.04%2Bdfsg-8
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 3,468 kB
  • sloc: ansic: 15,821; perl: 674; sh: 63; makefile: 29
file content (25 lines) | stat: -rw-r--r-- 552 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 <unistd.h>
#include "obuf.h"

/** Copy all the data from an input file descriptor to an \c obuf. */
int obuf_copyfromfd(int in, obuf* out)
{
  long rd;
  if (obuf_error(out)) return 0;
  out->count = 0;
  for (;;) {
    if ((rd = read(in,
		   out->io.buffer + out->bufpos,
		   out->io.bufsize - out->bufpos)) == -1)
      return 0;
    if (rd == 0)
      break;
    out->bufpos += rd;
    if (out->io.buflen < out->bufpos)
      out->io.buflen = out->bufpos;
    if (!obuf_flush(out))
      return 0;
    out->count += rd;
  }
  return 1;
}