ucx
UAP Common Extensions
Loading...
Searching...
No Matches
printf.h
Go to the documentation of this file.
1/*
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3 *
4 * Copyright 2021 Mike Becker, Olaf Wintermann All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
35
36#ifndef UCX_PRINTF_H
37#define UCX_PRINTF_H
38
39#include "common.h"
40#include "string.h"
41#include <stdarg.h>
42
48#define CX_PRINTF_ARGS(fmt_idx, arg_idx) \
49 __attribute__((__format__(printf, fmt_idx, arg_idx)))
50
54CX_EXPORT extern const unsigned cx_printf_sbo_size;
55
67int cx_fprintf(void *stream, cx_write_func wfc, const char *fmt, ...);
68
81int cx_vfprintf(void *stream, cx_write_func wfc, const char *fmt, va_list ap);
82
98cxmutstr cx_asprintf_a(const CxAllocator *allocator, const char *fmt, ...);
99
113#define cx_asprintf(fmt, ...) cx_asprintf_a(cxDefaultAllocator, fmt, __VA_ARGS__)
114
130cxmutstr cx_vasprintf_a(const CxAllocator *allocator, const char *fmt, va_list ap);
131
145#define cx_vasprintf(fmt, ap) cx_vasprintf_a(cxDefaultAllocator, fmt, ap)
146
157#define cx_bprintf(buffer, fmt, ...) cx_fprintf((void*)buffer, cxBufferWriteFunc, fmt, __VA_ARGS__)
158
159
173#define cx_sprintf(str, len, fmt, ...) cx_sprintf_a(cxDefaultAllocator, str, len, fmt, __VA_ARGS__)
174
192int cx_sprintf_a(const CxAllocator *alloc, char **str, size_t *len, const char *fmt, ...);
193
194
208#define cx_vsprintf(str, len, fmt, ap) cx_vsprintf_a(cxDefaultAllocator, str, len, fmt, ap)
209
227int cx_vsprintf_a(const CxAllocator *alloc, char **str, size_t *len, const char *fmt, va_list ap);
228
229
250#define cx_sprintf_s(buf, len, str, fmt, ...) cx_sprintf_sa(cxDefaultAllocator, buf, len, str, fmt, __VA_ARGS__)
251
275int cx_sprintf_sa(const CxAllocator *alloc, char *buf, size_t *len, char **str, const char *fmt, ...);
276
297#define cx_vsprintf_s(buf, len, str, fmt, ap) cx_vsprintf_sa(cxDefaultAllocator, buf, len, str, fmt, ap)
298
321int cx_vsprintf_sa(const CxAllocator *alloc, char *buf, size_t *len, char **str, const char *fmt, va_list ap);
322
323#endif //UCX_PRINTF_H
struct cx_allocator_s CxAllocator
High-Level type alias for the allocator type.
Definition allocator.h:80
Common definitions and feature checks.
#define CX_CSTR_ARG(idx)
No support for null_terminated_string_arg in clang or GCC below 14.
Definition common.h:211
size_t(* cx_write_func)(const void *, size_t, size_t, void *)
Function pointer compatible with fwrite-like functions.
Definition common.h:325
#define CX_EXPORT
Only used for building Windows DLLs.
Definition common.h:289
#define CX_NONNULL
All pointer arguments must be non-NULL.
Definition common.h:141
#define CX_NONNULL_ARG(...)
The specified pointer arguments must be non-NULL.
Definition common.h:146
#define CX_EXTERN
Declares a function with external linkage.
Definition common.h:297
#define CX_ACCESS_RW(...)
Specifies that the function will read and write through the given pointer.
Definition common.h:238
#define CX_PRINTF_ARGS(fmt_idx, arg_idx)
Attribute for printf-like functions.
Definition printf.h:48
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.
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_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_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_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_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.
Strings that know their length.
struct cx_mutstr_s cxmutstr
A mutable string.
Definition string.h:74