ibuf: Input Buffer Managemenet


Data Structures

struct  ibuf

Defines

#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))

Typedefs

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

Functions

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_getnetstring (ibuf *in, struct str *s)
int ibuf_readall (ibuf *in, struct str *s)
int ibuf_openreadclose (const char *filename, struct str *s)

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.


Typedef Documentation

typedef struct ibuf ibuf

Input specific buffer typedef.

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

ibuf read function pointer prototype.


Function Documentation

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_getnetstring ( ibuf in,
struct str s 
)

Read a netstring from the given ibuf .

If the input is not a netstring, errno (and in->io.errnum ) will be set to EPROTOTYPE and the state of in will be undefined.

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_openreadclose ( const char *  filename,
struct str out 
)

Open and read the entire file into the str .

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_readall ( ibuf in,
struct str out 
)

Read the remainder of the ibuf into the str.

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.


Variable Documentation

ibuf inbuf

Input buffer for stdin


Generated on Thu Feb 19 11:11:50 2009 for bglibs by  doxygen 1.5.4