nexmon – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | /* |
2 | * Wrappers for printf like functions. |
||
3 | * |
||
4 | * Wireshark - Network traffic analyzer |
||
5 | * By Gerald Combs <gerald@wireshark.org> |
||
6 | * Copyright 2007 Gerald Combs |
||
7 | * |
||
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. |
||
12 | * |
||
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. |
||
17 | * |
||
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. |
||
21 | */ |
||
22 | |||
23 | #ifndef __WS_PRINTF_H__ |
||
24 | #define __WS_PRINTF_H__ |
||
25 | |||
26 | /* |
||
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. |
||
31 | */ |
||
32 | |||
33 | #ifdef __cplusplus |
||
34 | extern "C" { |
||
35 | #endif /* __cplusplus */ |
||
36 | |||
37 | #ifdef _WIN32 |
||
38 | #include <strsafe.h> |
||
39 | |||
40 | #if _MSC_VER < 1900 |
||
41 | #include <stdarg.h> |
||
42 | |||
43 | /* |
||
44 | * vsnprintf_s's return value isn't compatible with C99 vsnprintf. We don't |
||
45 | * return anything in order to avoid confusion. |
||
46 | */ |
||
47 | |||
48 | static __inline void |
||
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); |
||
52 | } |
||
53 | |||
54 | #else /* _MSC_VER uses UCRT */ |
||
55 | |||
56 | /* The UCRT versions of snprintf and vsnprintf conform to C99 */ |
||
57 | |||
58 | static __inline void |
||
59 | ws_vsnprintf(char *buffer, size_t size_of_buffer, const char *format, va_list argptr) |
||
60 | { |
||
61 | vsnprintf(buffer, size_of_buffer, format, argptr); |
||
62 | } |
||
63 | |||
64 | #endif /* _MSC_VER */ |
||
65 | |||
66 | #else /* _WIN32 */ |
||
67 | |||
68 | #include <glib.h> |
||
69 | |||
70 | /* |
||
71 | * Use g_vsnprintf. On Linux and macOS these should be a thin wrapper around |
||
72 | * vsprintf. |
||
73 | */ |
||
74 | |||
75 | static inline void |
||
76 | ws_vsnprintf(char *buffer, size_t size_of_buffer, const char *format, va_list argptr) |
||
77 | { |
||
78 | g_vsnprintf(buffer, (gulong) size_of_buffer, format, argptr); |
||
79 | } |
||
80 | |||
81 | #endif /* _WIN32 */ |
||
82 | |||
83 | #ifdef _WIN32 |
||
84 | static __inline void |
||
85 | #else |
||
86 | static inline void |
||
87 | #endif |
||
88 | ws_snprintf(char *buffer, size_t size_of_buffer, const char * format, ...) { |
||
89 | va_list argptr; |
||
90 | |||
91 | va_start(argptr, format); |
||
92 | ws_vsnprintf(buffer, size_of_buffer, format, argptr); |
||
93 | va_end(argptr); |
||
94 | } |
||
95 | |||
96 | #ifdef __cplusplus |
||
97 | } |
||
98 | #endif /* __cplusplus */ |
||
99 | |||
100 | #endif /* __WS_PRINTF_H__ */ |