ucx
UAP Common Extensions
Loading...
Searching...
No Matches
Macros | Functions
printf.h File Reference

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.

Macros

#define cx_asprintf(fmt, ...)    cx_asprintf_a(cxDefaultAllocator, fmt, __VA_ARGS__)
 A asprintf like function which allocates space for a string the result is written to.
 
#define cx_vasprintf(fmt, ap)   cx_vasprintf_a(cxDefaultAllocator, 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.
 

Functions

int cx_fprintf (void *stream, cx_write_func wfc, char const *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, char const *fmt, va_list ap)
 A vfprintf like function which writes the output to a stream by using a write_func.
 
cxmutstr cx_asprintf_a (CxAllocator const *allocator, char const *fmt,...)
 A asprintf like function which allocates space for a string the result is written to.
 
cxmutstr cx_vasprintf_a (CxAllocator const *allocator, char const *fmt, va_list ap)
 A vasprintf like function which allocates space for a string the result is written to.
 

Detailed Description

Wrapper for write functions with a printf-like interface.

Author
Mike Becker
Olaf Wintermann
Version
3.0

Macro Definition Documentation

◆ cx_asprintf

#define cx_asprintf (   fmt,
  ... 
)     cx_asprintf_a(cxDefaultAllocator, fmt, __VA_ARGS__)

A asprintf like function which allocates space for a string the result is written to.

Note
The resulting string is guaranteed to be zero-terminated.
Parameters
fmtformat string
...additional arguments
Returns
the formatted string
See also
cx_strfree()

◆ cx_bprintf

#define cx_bprintf (   buffer,
  fmt,
  ... 
)
Value:
cx_fprintf((CxBuffer*)buffer, \
(cx_write_func) cxBufferWrite, fmt, __VA_ARGS__)
size_t cxBufferWrite(void const *ptr, size_t size, size_t nitems, CxBuffer *buffer)
Writes data to a CxBuffer.
size_t(* cx_write_func)(void const *, size_t, size_t, void *)
Function pointer compatible with fwrite-like functions.
Definition: common.h:103
int cx_fprintf(void *stream, cx_write_func wfc, char const *fmt,...)
A fprintf like function which writes the output to a stream by using a write_func.
Structure for the UCX buffer data.
Definition: buffer.h:73

A printf like function which writes the output to a CxBuffer.

Parameters
buffera pointer to the buffer the data is written to
fmtthe format string
...additional arguments
Returns
the total number of bytes written
See also
ucx_fprintf()

◆ cx_vasprintf

#define cx_vasprintf (   fmt,
  ap 
)    cx_vasprintf_a(cxDefaultAllocator, fmt, ap)

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.
Parameters
fmtformat string
apargument list
Returns
the formatted string
See also
cx_asprintf()

Function Documentation

◆ cx_asprintf_a()

cxmutstr cx_asprintf_a ( CxAllocator const *  allocator,
char const *  fmt,
  ... 
)

A asprintf like function which allocates space for a string the result is written to.

Note
The resulting string is guaranteed to be zero-terminated.
Parameters
allocatorthe CxAllocator used for allocating the string
fmtformat string
...additional arguments
Returns
the formatted string
See also
cx_strfree_a()

◆ cx_fprintf()

int cx_fprintf ( void *  stream,
cx_write_func  wfc,
char const *  fmt,
  ... 
)

A fprintf like function which writes the output to a stream by using a write_func.

Parameters
streamthe stream the data is written to
wfcthe write function
fmtformat string
...additional arguments
Returns
the total number of bytes written

◆ cx_vasprintf_a()

cxmutstr cx_vasprintf_a ( CxAllocator const *  allocator,
char const *  fmt,
va_list  ap 
)

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.
Parameters
allocatorthe CxAllocator used for allocating the string
fmtformat string
apargument list
Returns
the formatted string
See also
cx_asprintf_a()

◆ cx_vfprintf()

int cx_vfprintf ( void *  stream,
cx_write_func  wfc,
char const *  fmt,
va_list  ap 
)

A vfprintf like function which writes the output to a stream by using a write_func.

Parameters
streamthe stream the data is written to
wfcthe write function
fmtformat string
apargument list
Returns
the total number of bytes written
See also
cx_fprintf()