xref: /trunk/main/sal/inc/systools/win32/snprintf.h (revision 91144cd0085a7583d2099b982122deb2184ab956)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 #ifndef _SNPRINTF_H
22 #define _SNPRINTF_H
23 
24 #if     !defined(_WIN32)
25 #error ERROR: Only Win32 target supported!
26 #endif
27 
28 /* Macros for Unicode/ANSI support like in TCHAR.H */
29 
30 #ifdef _UNICODE
31 #define sntprintf   snwprintf
32 #define vsntprintf  vsnwprintf
33 #else
34 #define sntprintf   snprintf
35 #define vsntprintf  vsnprintf
36 #endif
37 
38 /* Define needed types if they are not yet defined */
39 
40 #if 0
41 #   ifndef _INC_STDARG
42 #   include <stdarg.h>
43 #   endif
44 #else
45 #   ifndef _VA_LIST_DEFINED
46     typedef char *  va_list;
47 #   define _VA_LIST_DEFINED
48 #   endif
49 #endif
50 
51 #if 0
52 #   ifndef _INC_WCHAR
53 #   include <wchar.h>
54 #   endif
55 #else
56 #   ifndef _WCHAR_T_DEFINED
57     typedef unsigned short wchar_t;
58 #   define _WCHAR_T_DEFINED
59 #   endif
60 #endif
61 
62 #ifndef _SNPRINTF_DLLIMPORT
63 #define _SNPRINTF_DLLIMPORT __declspec( dllimport )
64 #endif
65 
66 #ifdef __cplusplus
67 extern "C" {
68 #endif
69 
70 
71 /*  Implementations of snprintf following the ISO/IEC 9899:1999 (ISO C99)
72     standard.
73     The difference compared to _snprintf is that the buffer always is zero
74     terminated (unless count is zero) and the return value is the number of
75     characters (not including terminating zero) that would have been written
76     even if the buffer wasn't large
77     enough to hold the string. */
78 
79 
80 
81 /*  A C runtime from VS2015 onwards supplies a conforming snprintf of its own.
82     Declaring these alongside it is a redefinition with different linkage
83     (C2375), so on such a runtime the declarations are simply left out and the
84     CRT's own are used. Older runtimes, which is every one the XP-era targets
85     build against, keep the declarations exactly as before. */
86 #if !defined(_MSC_VER) || (_MSC_VER < 1900)
87 
88 /* UNICODE version */
89 _SNPRINTF_DLLIMPORT int __cdecl snwprintf( wchar_t *buffer, size_t count, const wchar_t *format, ... );
90 
91 /* SBCS and MBCS version */
92 _SNPRINTF_DLLIMPORT int __cdecl snprintf( char *buffer, size_t count, const char *format, ... );
93 
94 #endif
95 
96 /* Conflict with STL_port inline implementation */
97 #if 0
98 /* UNICODE version */
99 _SNPRINTF_DLLIMPORT int __cdecl vsnwprintf( wchar_t *buffer, size_t count, const wchar_t *format, va_list ap );
100 
101 /* SBCS and MBCS version */
102 _SNPRINTF_DLLIMPORT int __cdecl vsnprintf( char *buffer, size_t count, const char *format, va_list ap );
103 #endif
104 
105 #ifdef __cplusplus
106 }
107 #endif
108 
109 #endif /* _SNPRINTF_H */
110