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.
#include <stdlib.h>
#include <stdarg.h>
Go to the source code of this file.
Typedefs | |
typedef 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_vprep (buffer_t *b, const char *format, va_list ap) |
Determine the space needed to fill a buffer. | |
void | buffer_vprintf (buffer_t *b, const char *format, int size, va_list ap) |
Print the formatted output to the buffer. | |
void | 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. |
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_vprep | ( | buffer_t * | b, | |
const char * | format, | |||
va_list | ap | |||
) |
Determine the space needed to fill a buffer.
This function is to be used in conjunction with buffer_vprintf. This procedure does not call any of the va_(start|end) macros. The integer size returned is to be passed to buffer_vprintf. This procedure does not actually change the buffer.
b | The buffer to fill. | |
format | The format string. | |
ap | The variable argument list for the format string. |
void buffer_vprintf | ( | buffer_t * | b, | |
const char * | format, | |||
int | size, | |||
va_list | ap | |||
) |
Print the formatted output to the buffer.
The format string follows the same semantics as the UNIX vprintf function. The size argument is given by the buffer_vprep function. Neither buffer_vprep nor buffer_vprintf call the variable argument macros va_(start|end).
b | The buffer to fill. | |
format | The format string. | |
size | The integer size determined by buffer_vprep. | |
ap | The variable argument list for the format string. |
void 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.
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. |