2 * Wrappers for printf like functions.
4 * Wireshark - Network traffic analyzer
5 * By Gerald Combs <gerald@wireshark.org>
6 * Copyright 2007 Gerald Combs
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #ifndef __WS_PRINTF_H__
24 #define __WS_PRINTF_H__
27 * GLib's string utility routines are slow on windows, likely due to calling
28 * g_printf_string_upper_bound. Using ws_snprintf and ws_vsnprintf in hot
29 * code paths can speed up program execution. Otherwise you're probably safe
30 * sticking with g_snprintf and g_vsnprintf.
35 #endif /* __cplusplus */
44 * vsnprintf_s's return value isn't compatible with C99 vsnprintf. We don't
45 * return anything in order to avoid confusion.
49 ws_vsnprintf(char *buffer, size_t size_of_buffer, const char *format, va_list argptr) {
50 /* We could alternatively use StringCchVPrintfA */
51 vsnprintf_s(buffer, size_of_buffer, _TRUNCATE, format, argptr);
54 #else /* _MSC_VER uses UCRT */
56 /* The UCRT versions of snprintf and vsnprintf conform to C99 */
59 ws_vsnprintf(char *buffer, size_t size_of_buffer, const char *format, va_list argptr)
61 vsnprintf(buffer, size_of_buffer, format, argptr);
71 * Use g_vsnprintf. On Linux and macOS these should be a thin wrapper around
76 ws_vsnprintf(char *buffer, size_t size_of_buffer, const char *format, va_list argptr)
78 g_vsnprintf(buffer, (gulong) size_of_buffer, format, argptr);
88 ws_snprintf(char *buffer, size_t size_of_buffer, const char * format, ...) {
91 va_start(argptr, format);
92 ws_vsnprintf(buffer, size_of_buffer, format, argptr);
96 /* This is intended to fool checkAPIs.pl for places that have "debugging"
97 (using printf) usually wrapped in an #ifdef, but checkAPIs.pl isn't smart
98 enough to figure that out.
99 Dissectors should still try to use proto_tree_add_debug_text when the
100 debugging context has a protocol tree.
102 #define ws_debug_printf printf
104 /* This is intended to fool checkAPIs.pl for few places that have legitimate
105 use for g_warning. This should be used sparingly.
107 #define ws_g_warning g_warning
111 #endif /* __cplusplus */
113 #endif /* __WS_PRINTF_H__ */