Main Page | Modules | Data Structures | Directories | File List | Data Fields

Buf


Functions

int u_buf_reserve (u_buf_t *ubuf, size_t size)
 Enlarge the underlying memory block of the given buffer.
int u_buf_append (u_buf_t *ubuf, const void *data, size_t size)
 Append some data to the buffer.
int u_buf_load (u_buf_t *ubuf, const char *filename)
 Fill a buffer object with the content of a file.
int u_buf_detach (u_buf_t *ubuf)
 Release buffer's underlying memory block without freeing it.
size_t u_buf_size (u_buf_t *ubuf)
 Return the size of memory block allocated by the buffer.
size_t u_buf_len (u_buf_t *ubuf)
 Return the length of the buffer.
int u_buf_clear (u_buf_t *ubuf)
 Clear a buffer.
int u_buf_set (u_buf_t *ubuf, const void *data, size_t size)
 Set the value of a buffer.
void * u_buf_ptr (u_buf_t *ubuf)
 Return a pointer to the buffer internal momory block.
int u_buf_free (u_buf_t *ubuf)
 Free a buffer.
int u_buf_printf (u_buf_t *ubuf, const char *fmt,...)
 Append a string to the given buffer.
int u_buf_create (u_buf_t **pubuf)
 Create a new buffer.

Function Documentation

int u_buf_append u_buf_t ubuf,
const void *  data,
size_t  size
 

Append data of size size to the given buffer. If needed the buffer will be enlarged.

Parameters:
ubuf buffer object
data the data block to append
size size of data
Returns:
0 on success, not zero on failure

Definition at line 68 of file buf.c.

References u_buf_s::data, u_buf_s::len, u_buf_s::size, and u_buf_reserve().

Referenced by u_buf_set().

int u_buf_clear u_buf_t ubuf  ) 
 

Totally erase the content of the given buffer. The memory allocated by the buffer will not be released until u_buf_free() is called.

Parameters:
ubuf buffer object
Returns:
0 on success, not zero on failure

Definition at line 204 of file buf.c.

References u_buf_s::len.

Referenced by u_buf_load(), and u_buf_set().

int u_buf_create u_buf_t **  pubuf  ) 
 

Create a new buffer object and save its pointer to *ps.

Parameters:
pubuf on success will get the new buffer object
Returns:
0 on success, not zero on failure

Definition at line 348 of file buf.c.

References u_zalloc().

int u_buf_detach u_buf_t ubuf  ) 
 

Release the underlying memory block of the given buffer without calling free() on it. The caller must free the buffer later on (probably after using it somwhow).

Use u_buf_ptr() to get the pointer of the memory block, u_buf_size() to get its size and u_buf_len() to get its length.

Parameters:
ubuf buffer object
Returns:
0 on success, not zero on failure

Definition at line 145 of file buf.c.

References u_buf_s::data, u_buf_s::len, and u_buf_s::size.

int u_buf_free u_buf_t ubuf  ) 
 

Release all resources and free the given buffer object.

Parameters:
ubuf buffer object
Returns:
0 on success, not zero on failure

Definition at line 269 of file buf.c.

References u_buf_s::data, and u_free().

size_t u_buf_len u_buf_t ubuf  ) 
 

Return the length of data store in the given buffer.

Parameters:
ubuf buffer object
Returns:
the data buffer length

Definition at line 185 of file buf.c.

References u_buf_s::len.

int u_buf_load u_buf_t ubuf,
const char *  filename
 

Open filename and copy its whole content into the given buffer.

Parameters:
ubuf buffer object
filename the source filename
Returns:
0 on success, not zero on failure

Definition at line 100 of file buf.c.

References u_buf_s::data, u_buf_s::len, u_buf_clear(), and u_buf_reserve().

int u_buf_printf u_buf_t ubuf,
const char *  fmt,
  ...
 

Create a string from the printf-style arguments and append it to the given u_buf_t object.

The length of the appended string (NOT including the ending '\0') will be added to the current length of the buffer (u_buf_len).

Parameters:
ubuf buffer object
fmt printf-style format
... variable list of arguments
Returns:
0 on success, not zero on failure

Definition at line 298 of file buf.c.

References u_buf_s::data, u_buf_s::len, u_buf_s::size, and u_buf_reserve().

void* u_buf_ptr u_buf_t ubuf  ) 
 

Return a void* pointer to the memory block allocated by the buffer object.

Parameters:
ubuf buffer object
Returns:
0 on success, not zero on failure

Definition at line 251 of file buf.c.

References u_buf_s::data.

int u_buf_reserve u_buf_t ubuf,
size_t  size
 

Enlarge the buffer data block to (at least) size bytes.

Parameters:
ubuf buffer object
size requested size
Returns:
0 on success, not zero on failure

Definition at line 31 of file buf.c.

References u_buf_s::data, u_buf_s::size, and u_realloc().

Referenced by u_buf_append(), u_buf_load(), and u_buf_printf().

int u_buf_set u_buf_t ubuf,
const void *  data,
size_t  size
 

Set the value of ubuf to data. If needed the buffer object will alloc more memory to store the data value.

Parameters:
ubuf buffer object
data the value that will be copied into the buffer
size size of data
Returns:
0 on success, not zero on failure

Definition at line 227 of file buf.c.

References u_buf_append(), and u_buf_clear().

size_t u_buf_size u_buf_t ubuf  ) 
 

Return the size of memory block allocated by the buffer.

Parameters:
ubuf buffer object
Returns:
the data buffer length

Definition at line 167 of file buf.c.

References u_buf_s::size.


←Products
© 2005-2007 - KoanLogic S.r.l. - All rights reserved