Zephyr API Documentation  2.7.0-rc2
A Scalable Open Source RTOS
cbprintf.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#ifndef ZEPHYR_INCLUDE_SYS_CBPRINTF_H_
8#define ZEPHYR_INCLUDE_SYS_CBPRINTF_H_
9
10#include <stdarg.h>
11#include <stddef.h>
12#include <stdint.h>
13#include <toolchain.h>
14
15#ifdef CONFIG_CBPRINTF_LIBC_SUBSTS
16#include <stdio.h>
17#endif /* CONFIG_CBPRINTF_LIBC_SUBSTS */
18
19/* Determine if _Generic is supported.
20 * In general it's a C11 feature but it was added also in:
21 * - GCC 4.9.0 https://gcc.gnu.org/gcc-4.9/changes.html
22 * - Clang 3.0 https://releases.llvm.org/3.0/docs/ClangReleaseNotes.html
23 *
24 * @note Z_C_GENERIC is also set for C++ where functionality is implemented
25 * using overloading and templates.
26 */
27#ifndef Z_C_GENERIC
28#if defined(__cplusplus) || (((__STDC_VERSION__ >= 201112L) || \
29 ((__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) >= 40900) || \
30 ((__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__) >= 30000)))
31#define Z_C_GENERIC 1
32#else
33#define Z_C_GENERIC 0
34#endif
35#endif
36
37/* Z_C_GENERIC is used there */
39
40#ifdef __cplusplus
41extern "C" {
42#endif
43
51#ifdef __xtensa__
52#define CBPRINTF_PACKAGE_ALIGNMENT 16
53#elif defined(CONFIG_X86) && !defined(CONFIG_64BIT)
54/* sizeof(long double) is 12 on x86-32, which is not power of 2.
55 * So set it manually.
56 */
57#define CBPRINTF_PACKAGE_ALIGNMENT \
58 (IS_ENABLED(CONFIG_CBPRINTF_PACKAGE_LONGDOUBLE) ? \
59 16 : MAX(sizeof(double), sizeof(long long)))
60#else
61#define CBPRINTF_PACKAGE_ALIGNMENT \
62 (IS_ENABLED(CONFIG_CBPRINTF_PACKAGE_LONGDOUBLE) ? \
63 sizeof(long double) : MAX(sizeof(double), sizeof(long long)))
64#endif
65
76#define CBPRINTF_PACKAGE_ADD_STRING_IDXS BIT(0)
77
97typedef int (*cbprintf_cb)(/* int c, void *ctx */);
98
115#define CBPRINTF_MUST_RUNTIME_PACKAGE(skip, ... /* fmt, ... */) \
116 Z_CBPRINTF_MUST_RUNTIME_PACKAGE(skip, __VA_ARGS__)
117
147#define CBPRINTF_STATIC_PACKAGE(packaged, inlen, outlen, align_offset, flags, \
148 ... /* fmt, ... */) \
149 Z_CBPRINTF_STATIC_PACKAGE(packaged, inlen, outlen, \
150 align_offset, flags, __VA_ARGS__)
151
192__printf_like(4, 5)
193int cbprintf_package(void *packaged,
194 size_t len,
196 const char *format,
197 ...);
198
233int cbvprintf_package(void *packaged,
234 size_t len,
236 const char *format,
237 va_list ap);
238
265int cbprintf_fsc_package(void *in_packaged,
266 size_t in_len,
267 void *packaged,
268 size_t len);
269
288 void *ctx,
289 void *packaged);
290
317__printf_like(3, 4)
318int cbprintf(cbprintf_cb out, void *ctx, const char *format, ...);
319
345int cbvprintf(cbprintf_cb out, void *ctx, const char *format, va_list ap);
346
347#ifdef CONFIG_CBPRINTF_LIBC_SUBSTS
348
367__printf_like(2, 3)
368int fprintfcb(FILE * stream, const char *format, ...);
369
387int vfprintfcb(FILE *stream, const char *format, va_list ap);
388
405__printf_like(1, 2)
406int printfcb(const char *format, ...);
407
423int vprintfcb(const char *format, va_list ap);
424
448__printf_like(3, 4)
449int snprintfcb(char *str, size_t size, const char *format, ...);
450
473int vsnprintfcb(char *str, size_t size, const char *format, va_list ap);
474
475#endif /* CONFIG_CBPRINTF_LIBC_SUBSTS */
476
481#ifdef __cplusplus
482}
483#endif
484
485#endif /* ZEPHYR_INCLUDE_SYS_CBPRINTF_H_ */
int cbprintf(cbprintf_cb out, void *ctx, const char *format,...)
*printf-like output through a callback.
int printfcb(const char *format,...)
printf using Zephyrs cbprintf infrastructure.
int cbpprintf(cbprintf_cb out, void *ctx, void *packaged)
Generate the output for a previously captured format operation.
int vfprintfcb(FILE *stream, const char *format, va_list ap)
vfprintf using Zephyrs cbprintf infrastructure.
int fprintfcb(FILE *stream, const char *format,...)
fprintf using Zephyrs cbprintf infrastructure.
int vsnprintfcb(char *str, size_t size, const char *format, va_list ap)
vsnprintf using Zephyrs cbprintf infrastructure.
int cbvprintf(cbprintf_cb out, void *ctx, const char *format, va_list ap)
varargs-aware *printf-like output through a callback.
int cbprintf_fsc_package(void *in_packaged, size_t in_len, void *packaged, size_t len)
Convert package to fully self-contained (fsc) package.
int snprintfcb(char *str, size_t size, const char *format,...)
snprintf using Zephyrs cbprintf infrastructure.
int vprintfcb(const char *format, va_list ap)
vprintf using Zephyrs cbprintf infrastructure.
int cbvprintf_package(void *packaged, size_t len, uint32_t flags, const char *format, va_list ap)
Capture state required to output formatted data later.
int(* cbprintf_cb)()
Signature for a cbprintf callback function.
Definition: cbprintf.h:97
int cbprintf_package(void *packaged, size_t len, uint32_t flags, const char *format,...)
Capture state required to output formatted data later.
flags
Definition: http_parser.h:131
__UINT32_TYPE__ uint32_t
Definition: stdint.h:60
int FILE
Definition: stdio.h:23
Macros to abstract toolchain specific capabilities.