File: iobuf_copy.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-- 644 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 "iobuf.h"

/** Copy all the data from an \c ibuf to an \c obuf. */
int iobuf_copy(ibuf* in, obuf* out)
{
  if (ibuf_eof(in)) return 1;
  if (ibuf_error(in) || obuf_error(out)) return 0;
  for (;;) {
    if (!obuf_write_large(out,
			  in->io.buffer+in->io.bufstart,
			  in->io.buflen-in->io.bufstart))
      return 0;
    in->io.bufstart = in->io.buflen;
    if (!ibuf_refill(in))
      return ibuf_eof(in);
  }
}

/** Copy all the data from an \c ibuf to an \c obuf, and flush the
    \c obuf after writing is completed. */
int iobuf_copyflush(ibuf* in, obuf* out)
{
  if (!iobuf_copy(in, out)) return 0;
  return obuf_flush(out);
}