forked from rurban/safeclib
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_msvcrt.h
186 lines (175 loc) · 4.8 KB
/
test_msvcrt.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/*------------------------------------------------------------------
* test_msvcrt.h - Seperate safec from native msvcrt sec_api
*
* 2018 Reini Urban
*
* Copyright (c) 2018 Reini Urban
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*------------------------------------------------------------------
*/
#ifndef __TEST_MSVCRT_H__
#define __TEST_MSVCRT_H__
#include "config.h"
#include "safe_config.h"
#include "test_private.h"
#include <stdbool.h>
#ifndef __KERNEL__
#include <errno.h>
#endif
/* With static linkage we can enforce our -lsafec over -lc.
But not all. Some forceinline API's will still use msvcrt.
With shared linkage we always get native msvcrt.
*/
#if defined(TEST_MSVCRT) && (HAVE_NATIVE)
#define USE_MSVCRT
#endif
#ifndef __TEST_MSVCRT_C__
extern bool use_msvcrt;
#endif
void init_msvcrt(bool is_msvcrt, bool *msvcrtp);
void print_msvcrt(bool use_msvcrt);
void _err_msvc(int rc, const int n, const int winerr, int *errp, const char *f,
const unsigned l);
void _errno_msvc(const int n, const int winerr, int *errp, const char *f,
const unsigned l);
#define ERR_MSVC(n, winerr) \
_err_msvc((int)rc, n, winerr, &errs, __FUNCTION__, __LINE__)
#define NEGERR_MSVC(n, winerr) \
_err_msvc((int)rc, -(n), (winerr == EOF) ? EOF : -(winerr), &errs, \
__FUNCTION__, __LINE__)
#ifdef __KERNEL__
#define ERRNO_MSVC(n, winerr)
#define ERREOF_MSVC(n, winerr)
#else
#define ERRNO_MSVC(n, winerr) \
_errno_msvc(n, winerr, &errs, __FUNCTION__, __LINE__)
#define ERREOF_MSVC(n, winerr) \
_errno_msvc(n, winerr, &errs, __FUNCTION__, __LINE__); \
ERR(EOF)
#endif
#ifdef USE_MSVCRT
#undef CHECK_SLACK
#define CHECK_SLACK(a, b) EXPSTR(a, "")
#define CHECK_WSLACK(a, b) WEXPSTR(a, L"")
#endif
#ifdef USE_MSVCRT
#undef tmpnam_s
#undef gets_s
#undef asctime_s
#undef ctime_s
#undef getenv_s
#undef bsearch_s
#undef qsort_s
#undef memcpy_s
#undef memmove_s
#undef memset_s
#undef memset16_s
#undef memset32_s
#undef memcmp_s
#undef memcmp16_s
#undef memcmp32_s
#undef memcpy16_s
#undef memcpy32_s
#undef memmove16_s
#undef memmove32_s
#undef memzero_s
#undef memzero16_s
#undef memzero32_s
#undef memchr_s
#undef memrchr_s
#undef timingsafe_bcmp
#undef timingsafe_memcmp
#undef memccpy_s
#undef wmemcpy_s
#undef wmemmove_s
#undef wmemcmp_s
#undef strcat_s
#undef strcpy_s
#undef stpcpy_s
#undef strncat_s
#undef strncpy_s
#undef strnlen_s
#undef strtok_s
#undef sprintf_s
#undef vsprintf_s
#undef snprintf_s
#undef vsnprintf_s
#undef strerror_s
#undef strcmp_s
#undef strcasecmp_s
#undef strnatcmp_s
#undef strnatcasecmp_s
#undef strcasestr_s
#undef strcmpfld_s
#undef strcpyfld_s
#undef strcpyfldin_s
#undef strcpyfldout_s
#undef strcspn_s
#undef strfirstchar_s
#undef strfirstdiff_s
#undef strisalphanumeric_s
#undef strisascii_s
#undef strisdigit_s
#undef strishex_s
#undef strislowercase_s
#undef strismixedcase_s
#undef strispassword_s
#undef strisuppercase_s
#undef strlastchar_s
#undef strlastdiff_s
#undef strljustify_s
#undef strnterminate_s
#undef strpbrk_s
#undef strfirstsame_s
#undef strlastsame_s
#undef strprefix_s
#undef strremovews_s
#undef strspn_s
#undef strstr_s
#undef strchr_s
#undef strrchr_s
#undef strtolowercase_s
#undef strtouppercase_s
#undef strlwr_s
#undef strupr_s
#undef strzero_s
#undef strcoll_s
#undef strset_s
#undef strnset_s
#undef mbstowcs_s
#undef mbsrtowcs_s
#undef wcsrtombs_s
#undef wcstombs_s
#undef wcrtomb_s
#undef wctomb_s
#undef wcsnlen_s
#undef wcscpy_s
#undef wcsncpy_s
#undef wcscat_s
#undef wcsncat_s
#undef wcstok_s
#undef swprintf_s
#undef vswprintf_s
#endif
#endif /* __TEST_MSVCRT_H__ */