Wrapper for write-functions with a printf-like interface.
More...
#include "common.h"
#include "string.h"
#include <stdarg.h>
Go to the source code of this file.
|
| #define | CX_PRINTF_ARGS(fmt_idx, arg_idx) |
| | Attribute for printf-like functions.
|
| |
| #define | cx_asprintf(fmt, ...) |
| | An asprintf like function which allocates space for a string the result is written to.
|
| |
| #define | cx_vasprintf(fmt, ap) |
| | A vasprintf like function which allocates space for a string the result is written to.
|
| |
| #define | cx_bprintf(buffer, fmt, ...) |
| | A printf like function which writes the output to a CxBuffer.
|
| |
| #define | cx_sprintf(str, len, fmt, ...) |
| | An sprintf like function which reallocates the string when the buffer is not large enough.
|
| |
| #define | cx_vsprintf(str, len, fmt, ap) |
| | An sprintf like function which reallocates the string when the buffer is not large enough.
|
| |
| #define | cx_sprintf_s(buf, len, str, fmt, ...) |
| | An sprintf like function which allocates a new string when the buffer is not large enough.
|
| |
| #define | cx_vsprintf_s(buf, len, str, fmt, ap) |
| | An sprintf like function which allocates a new string when the buffer is not large enough.
|
| |
|
| int | cx_fprintf (void *stream, cx_write_func wfc, const char *fmt,...) |
| | A fprintf like function which writes the output to a stream by using a write_func.
|
| |
| int | cx_vfprintf (void *stream, cx_write_func wfc, const char *fmt, va_list ap) |
| | A vfprintf like function which writes the output to a stream by using a write_func.
|
| |
| cxmutstr | cx_asprintf_a (const CxAllocator *allocator, const char *fmt,...) |
| | An asprintf like function which allocates space for a string the result is written to.
|
| |
| cxmutstr | cx_vasprintf_a (const CxAllocator *allocator, const char *fmt, va_list ap) |
| | A vasprintf like function which allocates space for a string the result is written to.
|
| |
| int | cx_sprintf_a (const CxAllocator *alloc, char **str, size_t *len, const char *fmt,...) |
| | An sprintf like function which reallocates the string when the buffer is not large enough.
|
| |
| int | cx_vsprintf_a (const CxAllocator *alloc, char **str, size_t *len, const char *fmt, va_list ap) |
| | An sprintf like function which reallocates the string when the buffer is not large enough.
|
| |
| int | cx_sprintf_sa (const CxAllocator *alloc, char *buf, size_t *len, char **str, const char *fmt,...) |
| | An sprintf like function which allocates a new string when the buffer is not large enough.
|
| |
| int | cx_vsprintf_sa (const CxAllocator *alloc, char *buf, size_t *len, char **str, const char *fmt, va_list ap) |
| | An sprintf like function which allocates a new string when the buffer is not large enough.
|
| |
|
|
const unsigned | cx_printf_sbo_size |
| | The maximum string length that fits into stack memory.
|
| |
Wrapper for write-functions with a printf-like interface.
- Author
- Mike Becker
-
Olaf Wintermann
- Copyright
- 2-Clause BSD License
◆ cx_asprintf
| #define cx_asprintf |
( |
| fmt, |
|
|
| ... ) |
Value:
const CxAllocator * cxDefaultAllocator
The default allocator that is used by UCX.
cxmutstr cx_asprintf_a(const CxAllocator *allocator, const char *fmt,...)
An asprintf like function which allocates space for a string the result is written to.
An asprintf like function which allocates space for a string the result is written to.
- Note
- The resulting string is guaranteed to be zero-terminated, unless there was an error, in which case the string's pointer will be
NULL.
- Parameters
-
| fmt | (char*) format string |
| ... | additional arguments |
- Returns
- (
cxmutstr) the formatted string
- See also
- cx_strfree()
◆ cx_bprintf
| #define cx_bprintf |
( |
| buffer, |
|
|
| fmt, |
|
|
| ... ) |
Value:
#define cxBufferWriteFunc
Function pointer for cxBufferWrite that is compatible with cx_write_func.
Definition buffer.h:99
int cx_fprintf(void *stream, cx_write_func wfc, const char *fmt,...)
A fprintf like function which writes the output to a stream by using a write_func.
A printf like function which writes the output to a CxBuffer.
- Parameters
-
| buffer | (CxBuffer*) a pointer to the buffer the data is written to |
| fmt | (char*) the format string |
| ... | additional arguments |
- Returns
- (
int) the total number of bytes written or an error code from stdlib printf implementation
- See also
- cx_fprintf()
-
cxBufferWrite()
◆ CX_PRINTF_ARGS
| #define CX_PRINTF_ARGS |
( |
| fmt_idx, |
|
|
| arg_idx ) |
Value:
#define __attribute__(x)
Removes GNU C attributes where they are not supported.
Definition common.h:130
Attribute for printf-like functions.
- Parameters
-
| fmt_idx | index of the format string parameter |
| arg_idx | index of the first formatting argument |
◆ cx_sprintf
| #define cx_sprintf |
( |
| str, |
|
|
| len, |
|
|
| fmt, |
|
|
| ... ) |
Value:
int cx_sprintf_a(const CxAllocator *alloc, char **str, size_t *len, const char *fmt,...)
An sprintf like function which reallocates the string when the buffer is not large enough.
An sprintf like function which reallocates the string when the buffer is not large enough.
The size of the buffer will be updated in len when necessary.
- Note
- The resulting string, if successful, is guaranteed to be zero-terminated.
- Parameters
-
| str | (char**) a pointer to the string buffer |
| len | (size_t*) a pointer to the length of the buffer |
| fmt | (char*) the format string |
| ... | additional arguments |
- Returns
- (
int) the length of the produced string or an error code from stdlib printf implementation
◆ cx_sprintf_s
| #define cx_sprintf_s |
( |
| buf, |
|
|
| len, |
|
|
| str, |
|
|
| fmt, |
|
|
| ... ) |
Value:
int cx_sprintf_sa(const CxAllocator *alloc, char *buf, size_t *len, char **str, const char *fmt,...)
An sprintf like function which allocates a new string when the buffer is not large enough.
An sprintf like function which allocates a new string when the buffer is not large enough.
The size of the buffer will be updated in len when necessary.
The location of the resulting string will always be stored to str. When the buffer was sufficiently large, buf itself will be stored to the location of str.
- Note
- The resulting string, if successful, is guaranteed to be zero-terminated.
- Parameters
-
| buf | (char*) a pointer to the buffer |
| len | (size_t*) a pointer to the length of the buffer |
| str | (char**) a pointer where the location of the result shall be stored |
| fmt | (char*) the format string |
| ... | additional arguments |
- Returns
- (
int) the length of the produced string or an error code from stdlib printf implementation
◆ cx_vasprintf
| #define cx_vasprintf |
( |
| fmt, |
|
|
| ap ) |
Value:
cxmutstr cx_vasprintf_a(const CxAllocator *allocator, const char *fmt, va_list ap)
A vasprintf like function which allocates space for a string the result is written to.
A vasprintf like function which allocates space for a string the result is written to.
- Note
- The resulting string is guaranteed to be zero-terminated, unless there was an error, in which case the string's pointer will be
NULL.
- Parameters
-
| fmt | (char*) format string |
| ap | (va_list) argument list |
- Returns
- (
cxmutstr) the formatted string
- See also
- cx_asprintf()
◆ cx_vsprintf
| #define cx_vsprintf |
( |
| str, |
|
|
| len, |
|
|
| fmt, |
|
|
| ap ) |
Value:
int cx_vsprintf_a(const CxAllocator *alloc, char **str, size_t *len, const char *fmt, va_list ap)
An sprintf like function which reallocates the string when the buffer is not large enough.
An sprintf like function which reallocates the string when the buffer is not large enough.
The size of the buffer will be updated in len when necessary.
- Note
- The resulting string, if successful, is guaranteed to be zero-terminated.
- Parameters
-
| str | (char**) a pointer to the string buffer |
| len | (size_t*) a pointer to the length of the buffer |
| fmt | (char*) the format string |
| ap | (va_list) argument list |
- Returns
- (
int) the length of the produced string or an error code from stdlib printf implementation
◆ cx_vsprintf_s
| #define cx_vsprintf_s |
( |
| buf, |
|
|
| len, |
|
|
| str, |
|
|
| fmt, |
|
|
| ap ) |
Value:
int cx_vsprintf_sa(const CxAllocator *alloc, char *buf, size_t *len, char **str, const char *fmt, va_list ap)
An sprintf like function which allocates a new string when the buffer is not large enough.
An sprintf like function which allocates a new string when the buffer is not large enough.
The size of the buffer will be updated in len when necessary.
The location of the resulting string will always be stored to str. When the buffer was sufficiently large, buf itself will be stored to the location of str.
- Note
- The resulting string is guaranteed to be zero-terminated.
- Parameters
-
| buf | (char*) a pointer to the buffer |
| len | (size_t*) a pointer to the length of the buffer |
| str | (char**) a pointer where the location of the result shall be stored |
| fmt | (char*) the format string |
| ap | (va_list) argument list |
- Returns
- (
int) the length of the produced string or an error code from stdlib printf implementation
◆ cx_asprintf_a()
An asprintf like function which allocates space for a string the result is written to.
- Note
- The resulting string is guaranteed to be zero-terminated, unless there was an error, in which case the string's pointer will be
NULL.
- Parameters
-
| allocator | the CxAllocator used for allocating the string |
| fmt | format string |
| ... | additional arguments |
- Returns
- the formatted string
- See also
- cx_strfree_a()
◆ cx_fprintf()
| int cx_fprintf |
( |
void * | stream, |
|
|
cx_write_func | wfc, |
|
|
const char * | fmt, |
|
|
| ... ) |
A fprintf like function which writes the output to a stream by using a write_func.
- Parameters
-
| stream | the stream the data is written to |
| wfc | the write function |
| fmt | format string |
| ... | additional arguments |
- Returns
- the total number of bytes written or an error code from stdlib printf implementation
◆ cx_sprintf_a()
| int cx_sprintf_a |
( |
const CxAllocator * | alloc, |
|
|
char ** | str, |
|
|
size_t * | len, |
|
|
const char * | fmt, |
|
|
| ... ) |
An sprintf like function which reallocates the string when the buffer is not large enough.
The size of the buffer will be updated in len when necessary.
- Note
- The resulting string, if successful, is guaranteed to be zero-terminated.
- Attention
- The original buffer MUST have been allocated with the same allocator!
- Parameters
-
| alloc | the allocator to use |
| str | a pointer to the string buffer |
| len | a pointer to the length of the buffer |
| fmt | the format string |
| ... | additional arguments |
- Returns
- the length of the produced string or an error code from stdlib printf implementation
◆ cx_sprintf_sa()
| int cx_sprintf_sa |
( |
const CxAllocator * | alloc, |
|
|
char * | buf, |
|
|
size_t * | len, |
|
|
char ** | str, |
|
|
const char * | fmt, |
|
|
| ... ) |
An sprintf like function which allocates a new string when the buffer is not large enough.
The size of the buffer will be updated in len when necessary.
The location of the resulting string will always be stored to str. When the buffer was sufficiently large, buf itself will be stored to the location of str.
- Note
- The resulting string, if successful, is guaranteed to be zero-terminated.
- Parameters
-
| alloc | the allocator to use |
| buf | a pointer to the buffer |
| len | a pointer to the length of the buffer |
| str | a pointer where the location of the result shall be stored |
| fmt | the format string |
| ... | additional arguments |
- Returns
- the length of the produced string or an error code from stdlib printf implementation
◆ cx_vasprintf_a()
A vasprintf like function which allocates space for a string the result is written to.
- Note
- The resulting string is guaranteed to be zero-terminated, unless there was an error, in which case the string's pointer will be
NULL.
- Parameters
-
| allocator | the CxAllocator used for allocating the string |
| fmt | format string |
| ap | argument list |
- Returns
- the formatted string
- See also
- cx_asprintf_a()
◆ cx_vfprintf()
| int cx_vfprintf |
( |
void * | stream, |
|
|
cx_write_func | wfc, |
|
|
const char * | fmt, |
|
|
va_list | ap ) |
A vfprintf like function which writes the output to a stream by using a write_func.
- Parameters
-
| stream | the stream the data is written to |
| wfc | the write function |
| fmt | format string |
| ap | argument list |
- Returns
- the total number of bytes written or an error code from stdlib printf implementation
- See also
- cx_fprintf()
◆ cx_vsprintf_a()
| int cx_vsprintf_a |
( |
const CxAllocator * | alloc, |
|
|
char ** | str, |
|
|
size_t * | len, |
|
|
const char * | fmt, |
|
|
va_list | ap ) |
An sprintf like function which reallocates the string when the buffer is not large enough.
The size of the buffer will be updated in len when necessary.
- Note
- The resulting string is guaranteed to be zero-terminated.
- Attention
- The original buffer MUST have been allocated with the same allocator!
- Parameters
-
| alloc | the allocator to use |
| str | a pointer to the string buffer |
| len | a pointer to the length of the buffer |
| fmt | the format string |
| ap | argument list |
- Returns
- the length of the produced string or an error code from stdlib printf implementation
◆ cx_vsprintf_sa()
| int cx_vsprintf_sa |
( |
const CxAllocator * | alloc, |
|
|
char * | buf, |
|
|
size_t * | len, |
|
|
char ** | str, |
|
|
const char * | fmt, |
|
|
va_list | ap ) |
An sprintf like function which allocates a new string when the buffer is not large enough.
The size of the buffer will be updated in len when necessary.
The location of the resulting string will always be stored to str. When the buffer was sufficiently large, buf itself will be stored to the location of str.
- Note
- The resulting string is guaranteed to be zero-terminated.
- Parameters
-
| alloc | the allocator to use |
| buf | a pointer to the buffer |
| len | a pointer to the length of the buffer |
| str | a pointer where the location of the result shall be stored |
| fmt | the format string |
| ap | argument list |
- Returns
- the length of the produced string or an error code from stdlib printf implementation