2 * Wrappers for printf like functions.
4 * Wireshark - Network traffic analyzer
5 * By Gerald Combs <gerald@wireshark.org>
6 * Copyright 2007 Gerald Combs
8 * SPDX-License-Identifier: GPL-2.0-or-later
11 #ifndef __WS_PRINTF_H__
12 #define __WS_PRINTF_H__
15 * GLib's string utility routines are slow on windows, likely due to calling
16 * g_printf_string_upper_bound. Using ws_snprintf and ws_vsnprintf in hot
17 * code paths can speed up program execution. Otherwise you're probably safe
18 * sticking with g_snprintf and g_vsnprintf.
23 #endif /* __cplusplus */
32 * vsnprintf_s's return value isn't compatible with C99 vsnprintf. We don't
33 * return anything in order to avoid confusion.
37 ws_vsnprintf(char *buffer, size_t size_of_buffer, const char *format, va_list argptr) {
38 /* We could alternatively use StringCchVPrintfA */
39 vsnprintf_s(buffer, size_of_buffer, _TRUNCATE, format, argptr);
42 #else /* _MSC_VER uses UCRT */
44 /* The UCRT versions of snprintf and vsnprintf conform to C99 */
47 ws_vsnprintf(char *buffer, size_t size_of_buffer, const char *format, va_list argptr)
49 vsnprintf(buffer, size_of_buffer, format, argptr);
59 * Use g_vsnprintf. On Linux and macOS these should be a thin wrapper around
64 ws_vsnprintf(char *buffer, size_t size_of_buffer, const char *format, va_list argptr)
66 g_vsnprintf(buffer, (gulong) size_of_buffer, format, argptr);
76 ws_snprintf(char *buffer, size_t size_of_buffer, const char * format, ...) {
79 va_start(argptr, format);
80 ws_vsnprintf(buffer, size_of_buffer, format, argptr);
84 /* This is intended to fool checkAPIs.pl for places that have "debugging"
85 (using printf) usually wrapped in an #ifdef, but checkAPIs.pl isn't smart
86 enough to figure that out.
87 Dissectors should still try to use proto_tree_add_debug_text when the
88 debugging context has a protocol tree.
90 #define ws_debug_printf printf
92 /* This is intended to fool checkAPIs.pl for few places that have legitimate
93 use for g_warning. This should be used sparingly.
95 #define ws_g_warning g_warning
99 #endif /* __cplusplus */
101 #endif /* __WS_PRINTF_H__ */