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 */
37#ifndef UCX_PRINTF_H
38#define UCX_PRINTF_H
39
40#include "common.h"
41#include "string.h"
42#include <stdarg.h>
43
44#ifdef __cplusplus
45extern "C" {
46#endif
47
58__attribute__((__nonnull__(1, 2, 3), __format__(printf, 3, 4)))
60 void *stream,
61 cx_write_func wfc,
62 char const *fmt,
63 ...
64);
65
77__attribute__((__nonnull__))
79 void *stream,
80 cx_write_func wfc,
81 char const *fmt,
82 va_list ap
83);
84
97__attribute__((__nonnull__(1, 2), __format__(printf, 2, 3)))
99 CxAllocator const *allocator,
100 char const *fmt,
101 ...
102);
103
115#define cx_asprintf(fmt, ...) \
116 cx_asprintf_a(cxDefaultAllocator, fmt, __VA_ARGS__)
117
130__attribute__((__nonnull__))
132 CxAllocator const *allocator,
133 char const *fmt,
134 va_list ap
135);
136
148#define cx_vasprintf(fmt, ap) cx_vasprintf_a(cxDefaultAllocator, fmt, ap)
149
159#define cx_bprintf(buffer, fmt, ...) cx_fprintf((CxBuffer*)buffer, \
160 (cx_write_func) cxBufferWrite, fmt, __VA_ARGS__)
161
162#ifdef __cplusplus
163} // extern "C"
164#endif
165
166#endif //UCX_PRINTF_H
Common definitions and feature checks.
#define __attribute__(x)
Removes GNU C attributes where they are not supported.
Definition: common.h:127
size_t(* cx_write_func)(void const *, size_t, size_t, void *)
Function pointer compatible with fwrite-like functions.
Definition: common.h:103
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.
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_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.
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.
Strings that know their length.
Structure holding the data for an allocator.
Definition: allocator.h:86
The UCX string structure.
Definition: string.h:46