#ifndef UCX_PRINTF_H
#define UCX_PRINTF_H
#include "common.h"
#include "string.h"
#include <stdarg.h>
#ifdef __cplusplus
extern "C" {
#endif
extern unsigned const cx_printf_sbo_size;
__attribute__((__nonnull__(
1,
2,
3), __format__(printf,
3,
4)))
int cx_fprintf(
void *stream,
cx_write_func wfc,
char const *fmt,
...
);
__attribute__((__nonnull__))
int cx_vfprintf(
void *stream,
cx_write_func wfc,
char const *fmt,
va_list ap
);
__attribute__((__nonnull__(
1,
2), __format__(printf,
2,
3)))
cxmutstr cx_asprintf_a(
CxAllocator
const *allocator,
char const *fmt,
...
);
#define cx_asprintf(fmt, ...) \
cx_asprintf_a(cxDefaultAllocator, fmt,
__VA_ARGS__)
__attribute__((__nonnull__))
cxmutstr cx_vasprintf_a(
CxAllocator
const *allocator,
char const *fmt,
va_list ap
);
#define cx_vasprintf(fmt, ap) cx_vasprintf_a(cxDefaultAllocator, fmt, ap)
#define cx_bprintf(buffer, fmt, ...) cx_fprintf((CxBuffer*)buffer, \
(cx_write_func) cxBufferWrite, fmt,
__VA_ARGS__)
#define cx_sprintf(str, len, fmt, ...) cx_sprintf_a(cxDefaultAllocator, str, len, fmt,
__VA_ARGS__)
__attribute__((__nonnull__(
1,
2,
3,
4), __format__(printf,
4,
5)))
int cx_sprintf_a(CxAllocator *alloc,
char **str,
size_t *len,
const char *fmt, ... );
#define cx_vsprintf(str, len, fmt, ap) cx_vsprintf_a(cxDefaultAllocator, str, len, fmt, ap)
__attribute__((__nonnull__))
int cx_vsprintf_a(CxAllocator *alloc,
char **str,
size_t *len,
const char *fmt, va_list ap);
#define cx_sprintf_s(buf, len, str, fmt, ...) cx_sprintf_sa(cxDefaultAllocator, buf, len, str, fmt,
__VA_ARGS__)
__attribute__((__nonnull__(
1,
2,
4,
5), __format__(printf,
5,
6)))
int cx_sprintf_sa(CxAllocator *alloc,
char *buf,
size_t *len,
char **str,
const char *fmt, ... );
#define cx_vsprintf_s(buf, len, str, fmt, ap) cx_vsprintf_sa(cxDefaultAllocator, buf, len, str, fmt, ap)
__attribute__((__nonnull__))
int cx_vsprintf_sa(CxAllocator *alloc,
char *buf,
size_t *len,
char **str,
const char *fmt, va_list ap);
#ifdef __cplusplus
}
#endif
#endif