cctools
|
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_t * | buffer_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,...) |
Appends the formatted output to the buffer. | |
const char * | buffer_tostring (buffer_t *b, size_t *size) |
Returns the buffer as a string. |
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.
buffer_t* buffer_create | ( | void | ) |
Create a new buffer.
void buffer_delete | ( | buffer_t * | b | ) |
Delete a buffer.
b | The 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.
b | The buffer to fill. |
format | The format string. |
ap | The variable argument list for the format string. |
int buffer_printf | ( | buffer_t * | b, |
const char * | format, | ||
... | |||
) |
Appends the formatted output to the buffer.
The format string follows the same semantics as the UNIX vprintf function.
b | The buffer to fill. |
format | The format string. |
... | The variable arguments for the format string. |
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.
b | The buffer. |
size | The size of the string is placed in this variable. |