cctools
Typedefs | Functions
buffer.h File Reference

String Buffer Operations. More...

#include <stdlib.h>
#include <stdarg.h>

Go to the source code of this file.

Typedefs

typedef struct buffer_t buffer_t
 buffer_t is an opaque object representing a buffer.

Functions

buffer_tbuffer_create (void)
 Create a new buffer.
void buffer_delete (buffer_t *b)
 Delete a buffer.
int buffer_vprintf (buffer_t *b, const char *format, va_list ap)
 Print the formatted output to the buffer.
int buffer_printf (buffer_t *b, const char *format,...)
 Print the formatted output to the buffer.
const char * buffer_tostring (buffer_t *b, size_t *size)
 Returns the buffer as a string.

Detailed Description

String Buffer Operations.

You can use the buffer in the same way you would print to a file. Use the buffer to do formatted printing. When you are done retrieve the final string using buffer_tostring.


Typedef Documentation

typedef struct buffer_t buffer_t

buffer_t is an opaque object representing a buffer.


Function Documentation

buffer_t* buffer_create ( void  )

Create a new buffer.

Returns:
A new empty buffer object. Returns NULL when out of memory.
void buffer_delete ( buffer_t b)

Delete a buffer.

Parameters:
bThe buffer to free.
int buffer_vprintf ( buffer_t b,
const char *  format,
va_list  ap 
)

Print the formatted output to the buffer.

The format string follows the same semantics as the UNIX vprintf function. buffer_vprintf does not call the variable argument macros va_(start|end) on ap.

Parameters:
bThe buffer to fill.
formatThe format string.
apThe variable argument list for the format string.
Returns:
Negative value on error.
int buffer_printf ( buffer_t b,
const char *  format,
  ... 
)

Print the formatted output to the buffer.

The format string follows the same semantics as the UNIX vprintf function.

Parameters:
bThe buffer to fill.
formatThe format string.
...The variable arguments for the format string.
Returns:
Negative value on error.
const char* buffer_tostring ( buffer_t b,
size_t *  size 
)

Returns the buffer as a string.

The string is no longer valid after deleting the buffer. A final ASCII NUL character is guaranteed to terminate the string.

Parameters:
bThe buffer.
sizeThe size of the string is placed in this variable.
Returns:
The buffer as a string with a NUL terminator.