Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Related Pages

iobuf: I/O Buffer Management


Data Structures

struct  ibuf
 Input specific buffer. More...

struct  iobuf
 The base I/O buffer structure. More...

struct  obuf
 Output specific buffer. More...


Status Flags

#define IOBUF_EOF   1
#define IOBUF_ERROR   2
#define IOBUF_TIMEOUT   4
#define IOBUF_BADFLAGS   0xf
#define IOBUF_SEEKABLE   0x10
#define IOBUF_NEEDSCLOSE   0x20
#define IOBUF_NEEDSFREE   0x40
#define IOBUF_NEEDSMUNMAP   0x80
unsigned iobuf_bufsize

Common

#define IOBUF_SET_ERROR(io)
#define iobuf_closed(io)   ((io)->fd == -1)
#define iobuf_error(io)   ((io)->flags & IOBUF_ERROR)
#define iobuf_timedout(io)   ((io)->flags & IOBUF_TIMEOUT)
#define iobuf_bad(io)   ((io)->flags & IOBUF_BADFLAGS)
typedef iobuf iobuf
int iobuf_init (iobuf *io, int fd, unsigned bufsize, char *buffer, unsigned flags)
int iobuf_close (iobuf *io)
int iobuf_timeout (iobuf *io, int poll_out)

ibuf: Input

#define ibuf_close(in)   iobuf_close(&((in)->io))
#define ibuf_closed(in)   iobuf_closed(&((in)->io))
#define ibuf_error(in)   iobuf_error(&((in)->io))
#define ibuf_timedout(in)   iobuf_timedout(&((in)->io))
#define ibuf_rewind(in)   ibuf_seek(in,0)
#define ibuf_seekfwd(in, off)   ibuf_seek(ibuf_tell(in)+(offset))
typedef int(* ibuf_fn )(int, void *, unsigned long)
typedef ibuf ibuf
int ibuf_init (ibuf *in, int fd, ibuf_fn fn, unsigned flags, unsigned bufsize)
int ibuf_open (ibuf *in, const char *filename, unsigned bufsize)
int ibuf_eof (ibuf *in)
int ibuf_refill (ibuf *in)
int ibuf_read_large (ibuf *in, char *data, unsigned datalen)
int ibuf_read (ibuf *in, char *data, unsigned datalen)
unsigned ibuf_tell (ibuf *in)
int ibuf_seek (ibuf *in, unsigned offset)
int ibuf_peek (ibuf *in, char *ch)
int ibuf_getc (ibuf *in, char *ch)
int ibuf_getu (ibuf *in, unsigned long *data)
int ibuf_gets (ibuf *in, char *data, unsigned datalen, char boundary)
int ibuf_getstr (ibuf *in, struct str *s, char boundary)
int ibuf_getstr_crlf (ibuf *in, struct str *s)
int ibuf_readall (ibuf *in, struct str *s)
int ibuf_openreadclose (const char *filename, struct str *s)
ibuf inbuf

obuf: Output

#define OBUF_CREATE   O_CREAT
#define OBUF_EXCLUSIVE   O_EXCL
#define OBUF_TRUNCATE   O_TRUNC
#define OBUF_APPEND   O_APPEND
#define obuf_error(out)   iobuf_error(&(out)->io)
#define obuf_closed(out)   iobuf_closed(&(out)->io)
#define obuf_timedout(out)   iobuf_timedout(&((out)->io))
#define obuf_rewind(out)   obuf_seek(out,0)
#define obuf_tell(out)   ((out)->io.offset+(out)->bufpos)
#define obuf_puts(out, str)   obuf_write(out,str,strlen(str))
#define obuf_putstr(out, str)   obuf_write(out,(str)->s,(str)->len)
typedef int(* obuf_fn )(int, const void *, unsigned long)
typedef obuf obuf
int obuf_init (obuf *out, int fd, obuf_fn fn, unsigned flags, unsigned bufsize)
int obuf_open (obuf *out, const char *filename, int oflags, int mode, unsigned bufsize)
int obuf_close (obuf *out)
int obuf_flush (obuf *out)
int obuf_sync (obuf *out)
int obuf_write_large (obuf *out, const char *data, unsigned datalen)
int obuf_write (obuf *out, const char *data, unsigned datalen)
int obuf_seek (obuf *out, unsigned offset)
int obuf_pad (obuf *out, unsigned width, char ch)
int obuf_endl (obuf *out)
int obuf_putc (obuf *out, char ch)
int obuf_put2s (obuf *out, const char *s1, const char *s2)
int obuf_put3s (obuf *out, const char *s1, const char *s2, const char *s3)
int obuf_put4s (obuf *out, const char *s1, const char *s2, const char *s3, const char *s4)
int obuf_put5s (obuf *out, const char *s1, const char *s2, const char *s3, const char *s4, const char *s5)
int obuf_put6s (obuf *out, const char *s1, const char *s2, const char *s3, const char *s4, const char *s5, const char *s6)
int obuf_put7s (obuf *out, const char *s1, const char *s2, const char *s3, const char *s4, const char *s5, const char *s6, const char *s7)
int obuf_putns (obuf *out, unsigned int count,...)
int obuf_putsflush (obuf *out, const char *s)
int obuf_puti (obuf *out, long data)
int obuf_putiw (obuf *out, long data, unsigned width, char pad)
int obuf_putu (obuf *out, unsigned long data)
int obuf_putuw (obuf *out, unsigned long data, unsigned width, char pad)
int obuf_putill (obuf *out, long long data)
int obuf_putiwll (obuf *out, long long data, unsigned width, char pad)
int obuf_putull (obuf *out, unsigned long long data)
int obuf_putuwll (obuf *out, unsigned long long data, unsigned width, char pad)
int obuf_putx (obuf *out, unsigned long data)
int obuf_putxw (obuf *out, unsigned long data, unsigned width, char pad)
int obuf_putX (obuf *out, unsigned long data)
int obuf_putXw (obuf *out, unsigned long data, unsigned width, char pad)
int obuf_putxll (obuf *out, unsigned long long data)
int obuf_putxwll (obuf *out, unsigned long long data, unsigned width, char pad)
int obuf_putXll (obuf *out, unsigned long long data)
int obuf_putXwll (obuf *out, unsigned long long data, unsigned width, char pad)
int obuf_putsnumw (obuf *out, long num, unsigned width, char pad, unsigned base, const char *digits)
int obuf_putunumw (obuf *out, unsigned long num, unsigned width, char pad, unsigned base, const char *digits)
int obuf_putsllnumw (obuf *out, long long num, unsigned width, char pad, unsigned base, const char *digits)
int obuf_putullnumw (obuf *out, unsigned long long num, unsigned width, char pad, unsigned base, const char *digits)
int obuf_putnetstring (obuf *out, const char *data, unsigned datalen)
int obuf_sign_pad (obuf *out, int sign, unsigned width, char pad)
obuf outbuf
obuf errbuf
const char obuf_dec_digits [10]
const char obuf_hex_lcase_digits [16]
const char obuf_hex_ucase_digits [16]

Mass copying functions.

int iobuf_copy (ibuf *in, obuf *out)
int iobuf_copyflush (ibuf *in, obuf *out)
int ibuf_copytofd (ibuf *in, int out)
int obuf_copyfromfd (int in, obuf *out)

Variables

ibuf inbuf

Detailed Description

Calling Convention
Unless otherwise specified, the return value is non-zero (true) if the entire requested operation completed, and 0 (false) otherwise.

Define Documentation

#define ibuf_close (  in   )     iobuf_close(&((in)->io))
 

Close the ibuf.

#define ibuf_closed (  in   )     iobuf_closed(&((in)->io))
 

Test if the ibuf has been closed.

#define ibuf_error (  in   )     iobuf_error(&((in)->io))
 

Test if the ibuf is in an error state.

#define ibuf_rewind (  in   )     ibuf_seek(in,0)
 

Set the effective read position to the start of the file.

#define ibuf_seekfwd (  in,
off   )     ibuf_seek(ibuf_tell(in)+(offset))
 

Set the effective read position off bytes forward.

#define ibuf_timedout (  in   )     iobuf_timedout(&((in)->io))
 

Test if the last ibuf read timed out.

#define iobuf_bad (  io   )     ((io)->flags & IOBUF_BADFLAGS)
 

True if the iobuf is in a "bad" state.

#define IOBUF_BADFLAGS   0xf
 

Mask of all the error type flags.

#define iobuf_closed (  io   )     ((io)->fd == -1)
 

True if the iobuf has been closed.

#define IOBUF_EOF   1
 

Reading reached end of file.

#define iobuf_error (  io   )     ((io)->flags & IOBUF_ERROR)
 

True if the iobuf has an error flag.

#define IOBUF_ERROR   2
 

The iobuf has encountered an error.

#define IOBUF_NEEDSCLOSE   0x20
 

The file descriptor needs to be closed.

#define IOBUF_NEEDSFREE   0x40
 

The buffer needs to be deallocated with free.

#define IOBUF_NEEDSMUNMAP   0x80
 

The buffer needs to be deallocated with munmap.

#define IOBUF_SEEKABLE   0x10
 

lseek is possible on the file descriptor.

#define IOBUF_SET_ERROR (  io   ) 
 

Value:

do{ \
  io->flags |= IOBUF_ERROR; \
  io->errnum = errno; \
  return 0; \
}while(0)
Set the error flag, save errno, and return false.

#define iobuf_timedout (  io   )     ((io)->flags & IOBUF_TIMEOUT)
 

True if the input or output to the iobuf previously timed out.

#define IOBUF_TIMEOUT   4
 

The timeout expired before the read or write could be completed.

#define OBUF_APPEND   O_APPEND
 

All writes go to the end of the file.

#define obuf_closed (  out   )     iobuf_closed(&(out)->io)
 

Test if the obuf has been closed.

#define OBUF_CREATE   O_CREAT
 

Create the file if it does not already exist.

#define obuf_error (  out   )     iobuf_error(&(out)->io)
 

Test if the obuf is in an error state.

#define OBUF_EXCLUSIVE   O_EXCL
 

If OBUF_CREATE is set, fail to create the file if it already exists.

#define obuf_puts (  out,
str   )     obuf_write(out,str,strlen(str))
 

Write a C string to the obuf.

#define obuf_putstr (  out,
str   )     obuf_write(out,(str)->s,(str)->len)
 

Write a dynamic string to the iobuf.

#define obuf_rewind (  out   )     obuf_seek(out,0)
 

Set the effective write position to the start of the file.

#define obuf_tell (  out   )     ((out)->io.offset+(out)->bufpos)
 

Look up the current effective write position.

#define obuf_timedout (  out   )     iobuf_timedout(&((out)->io))
 

Test if the last obuf write timed out.

#define OBUF_TRUNCATE   O_TRUNC
 

If the file exists, truncate it to length 0.


Typedef Documentation

typedef int(* ibuf_fn)(int, void*, unsigned long)
 

ibuf read function pointer prototype.

typedef int(* obuf_fn)(int, const void*, unsigned long)
 

obuf write function pointer prototype.


Function Documentation

int ibuf_copytofd (  ibuf *  in,
int  out
) 
 

Copy all the data from an ibuf to a file descriptor.

int ibuf_eof (  ibuf *  in  ) 
 

Test if the ibuf has reaced end of file.

int ibuf_getc (  ibuf *  in,
char *  ch
) 
 

Retrieve a single character from the ibuf.

int ibuf_gets (  ibuf *  in,
char *  data,
unsigned  datalen,
char  boundary
) 
 

Read a line from the ibuf into a C string.

int ibuf_getstr (  ibuf *  in,
struct str *  s,
char  boundary
) 
 

Read a line from the ibuf into a dynamic string.

int ibuf_getstr_crlf (  ibuf *  in,
struct str *  s
) 
 

Read a line from the ibuf into a dynamic string, terminated by a CR+LF pair.

int ibuf_getu (  ibuf *  in,
unsigned long *  data
) 
 

Read an unsigned long from the ibuf.

int ibuf_init (  ibuf *  in,
int  fd,
ibuf_fn  fn,
unsigned  flags,
unsigned  bufsize
) 
 

Initialize an ibuf from an already-opened file descriptor.

int ibuf_open (  ibuf *  in,
const char *  filename,
unsigned  bufsize
) 
 

Initialize an ibuf by opening a file for reading.

int ibuf_peek (  ibuf *  in,
char *  ch
) 
 

Retrieve the next character in the ibuf without advancing the current read position.

int ibuf_read (  ibuf *  in,
char *  data,
unsigned  datalen
) 
 

Read a block of data from the ibuf.

Returns true only if the entire block was read. If the return value is false, the caller will need to check if a partial block was read.

int ibuf_read_large (  ibuf *  in,
char *  data,
unsigned  datalen
) 
 

Read a block of data from the ibuf.

This routine differs from ibuf_read in that the data is, as much as is possible, read directly into the given buffer, rather than first being read into the iobuf buffer and then into the given buffer. ibuf_read automatically calls this routine if the requested datalen is larger than or equal to the iobuf buffer size.

int ibuf_refill (  ibuf *  in  ) 
 

(Re)fill the buffer from the file descriptor.

Note:
This function may only be called when the buffer is completely empty.

int ibuf_seek (  ibuf *  in,
unsigned  offset
) 
 

Set the effective read position.

unsigned ibuf_tell (  ibuf *  in  ) 
 

Look up the current effective read position.

int iobuf_close (  iobuf *  io  ) 
 

Close an iobuf and deallocate the buffer.

int iobuf_copy (  ibuf *  in,
obuf *  out
) 
 

Copy all the data from an ibuf to an obuf.

int iobuf_copyflush (  ibuf *  in,
obuf *  out
) 
 

Copy all the data from an ibuf to an obuf, and flush the obuf after writing is completed.

int iobuf_init (  iobuf *  io,
int  fd,
unsigned  bufsize,
char *  buffer,
unsigned  flags
) 
 

Initialize an iobuf structure.

int iobuf_timeout (  iobuf *  io,
int  poll_out
) 
 

Wait for a file descriptor to be ready for reading or writing.

int obuf_close (  obuf *  out  ) 
 

Flush and close the obuf.

int obuf_copyfromfd (  int  in,
obuf *  out
) 
 

Copy all the data from an ibuf to an obuf.

int obuf_endl (  obuf *  out  ) 
 

Write a newline to the obuf and flush it.

int obuf_flush (  obuf *  out  ) 
 

Write all pending data in the obuf to the file descriptor.

int obuf_init (  obuf *  out,
int  fd,
obuf_fn  fn,
unsigned  flags,
unsigned  bufsize
) 
 

Initialize an obuf from an already-opened file descriptor.

int obuf_open (  obuf *  out,
const char *  filename,
int  oflags,
int  mode,
unsigned  bufsize
) 
 

Initialize an obuf by opening a file for writing.

int obuf_pad (  obuf *  out,
unsigned  width,
char  ch
) 
 

Pad the output with width instances of the single character ch.

int obuf_put2s (  obuf *  out,
const char *  s1,
const char *  s2
) 
 

Write 2 C strings to the obuf.

int obuf_put3s (  obuf *  out,
const char *  s1,
const char *  s2,
const char *  s3
) 
 

Write 3 C strings to the obuf.

int obuf_put4s (  obuf *  out,
const char *  s1,
const char *  s2,
const char *  s3,
const char *  s4
) 
 

Write 4 C strings to the obuf.

int obuf_put5s (  obuf *  out,
const char *  s1,
const char *  s2,
const char *  s3,
const char *  s4,
const char *  s5
) 
 

Write 5 C strings to the obuf.

int obuf_put6s (  obuf *  out,
const char *  s1,
const char *  s2,
const char *  s3,
const char *  s4,
const char *  s5,
const char *  s6
) 
 

Write 6 C strings to the obuf.

int obuf_put7s (  obuf *  out,
const char *  s1,
const char *  s2,
const char *  s3,
const char *  s4,
const char *  s5,
const char *  s6,
const char *  s7
) 
 

Write 7 C strings to the obuf.

int obuf_putc (  obuf *  out,
char  ch
) 
 

Write a single character to the obuf.

int obuf_puti (  obuf *  out,
long  data
) 
 

Write a signed integer as decimal to the obuf.

int obuf_putill (  obuf *  out,
long long  data
) 
 

Write a signed long long integer as decimal to the obuf.

int obuf_putiw (  obuf *  out,
long  data,
unsigned  width,
char  pad
) 
 

Write a signed integer as decimal to the obuf with padding.

int obuf_putiwll (  obuf *  out,
long long  data,
unsigned  width,
char  pad
) 
 

Write a signed long long integer as decimal to the obuf with padding.

int obuf_putnetstring (  obuf *  out,
const char *  data,
unsigned  datalen
) 
 

Write the binary block to the obuf as a "netstring".

int obuf_putns (  obuf *  out,
unsigned int  count,
... 
) 
 

Write N C strings to the obuf.

int obuf_putsflush (  obuf *  out,
const char *  s
) 
 

Write a C string to the obuf and flush it.

int obuf_putsllnumw (  obuf *  out,
long long  num,
unsigned  width,
char  pad,
unsigned  base,
const char *  digits
) 
 

Write a signed long long integer to the obuf with optional padding.

int obuf_putsnumw (  obuf *  out,
long  num,
unsigned  width,
char  pad,
unsigned  base,
const char *  digits
) 
 

Write a signed integer to the obuf with optional padding.

int obuf_putu (  obuf *  out,
unsigned long  data
) 
 

Write an unsigned integer as decimal to the obuf.

int obuf_putull (  obuf *  out,
unsigned long long  data
) 
 

Write an unsigned long long integer as decimal to the obuf.

int obuf_putullnumw (  obuf *  out,
unsigned long long  num,
unsigned  width,
char  pad,
unsigned  base,
const char *  digits
) 
 

Write an unsigned long long integer to the obuf with optional padding.

int obuf_putunumw (  obuf *  out,
unsigned long  num,
unsigned  width,
char  pad,
unsigned  base,
const char *  digits
) 
 

Write an unsigned integer to the obuf with optional padding.

int obuf_putuw (  obuf *  out,
unsigned long  data,
unsigned  width,
char  pad
) 
 

Write an unsigned integer as decimal to the obuf with padding.

int obuf_putuwll (  obuf *  out,
unsigned long long  data,
unsigned  width,
char  pad
) 
 

Write an unsigned long long integer as decimal to the obuf with padding.

int obuf_putX (  obuf *  out,
unsigned long  data
) 
 

Write an unsigned integer as (upper-case) hexadecimal to the obuf.

int obuf_putx (  obuf *  out,
unsigned long  data
) 
 

Write an unsigned integer as (lower-case) hexadecimal to the obuf.

int obuf_putXll (  obuf *  out,
unsigned long long  data
) 
 

Write an unsigned long long integer as (upper-case) hexadecimal to the obuf.

int obuf_putxll (  obuf *  out,
unsigned long long  data
) 
 

Write an unsigned long long integer as (lower-case) hexadecimal to the obuf.

int obuf_putXw (  obuf *  out,
unsigned long  data,
unsigned  width,
char  pad
) 
 

Write an unsigned integer as (upper-case) hexadecimal to the obuf with padding.

int obuf_putxw (  obuf *  out,
unsigned long  data,
unsigned  width,
char  pad
) 
 

Write an unsigned integer as (lower-case) hexadecimal to the obuf with padding.

int obuf_putXwll (  obuf *  out,
unsigned long long  data,
unsigned  width,
char  pad
) 
 

Write an unsigned long long integer as (upper-case) hexadecimal to the obuf with padding.

int obuf_putxwll (  obuf *  out,
unsigned long long  data,
unsigned  width,
char  pad
) 
 

Write an unsigned long long integer as (lower-case) hexadecimal to the obuf with padding.

int obuf_seek (  obuf *  out,
unsigned  offset
) 
 

Set the effective write position.

int obuf_sync (  obuf *  out  ) 
 

Flush the obuf and then fsync the file descriptor.

int obuf_write (  obuf *  out,
const char *  data,
unsigned  datalen
) 
 

Write a block of data to the obuf.

int obuf_write_large (  obuf *  out,
const char *  data,
unsigned  datalen
) 
 

Write a large block of data to the obuf, avoiding copying.


Variable Documentation

obuf errbuf
 

Output buffer for stderr.

ibuf inbuf
 

Input buffer for stdin.

ibuf inbuf
 

Initial value:

 { { 0, buffer, 4096, 0, 0, 0, 0, IOBUF_NEEDSCLOSE, 0 },
               0, (ibuf_fn)read }
Input buffer for stdin.

unsigned iobuf_bufsize
 

The default iobuf buffer size, defaults to 8192.

obuf outbuf
 

Output buffer for stdout.


Generated on Tue Mar 23 21:58:09 2004 for bglibs by doxygen 1.3.5