libUPnP 1.14.19
posix_overwrites.h
1#ifndef POSIX_OVERWRITES_H
2#define POSIX_OVERWRITES_H
3
4#ifdef _WIN32
5
6 /* POSIX names for functions */
7 #define fileno _fileno
8 #define unlink _unlink
9 #define strcasecmp _stricmp
10 #define strdup _strdup
11 #define stricmp _stricmp
12 #define strncasecmp strnicmp
13 #define strnicmp _strnicmp
14
15 /* Secure versions of functions */
16 /* Explicitly disable warnings by pragma/define, see:
17 * https://www.codegrepper.com/code-examples/c/crt+secure+no+warnings */
18 #pragma warning(disable : 4996)
19 #define _CRT_SECURE_NO_WARNINGS
20 #if 0
21 /*
22 * The current issues with those 4 defines:
23 * - strncpy redefinition is wrong
24 * - Theses functions assume they are being called on C arrays
25 * only. Using `countof` on a heap allocated pointer is
26 * undefined behavior and `sizeof` will only return the byte
27 * size of the pointer.
28 *
29 * The reason we can't pin-point the places where it fails is
30 * because *_s functions have a significantly different
31 * behaviour than the replaced functions and have actual error
32 * returns values that are simply ignored here, leading to
33 * numerous unseen regressions.
34 *
35 * A first step could be to actually crash or log on _s failures
36 * to detect the potentials overflows or bad usages of the
37 * wrappers.
38 */
39 #define strcat(arg1, arg2) strcat_s(arg1, sizeof(arg1), arg2)
40 #define strcpy(arg1, arg2) strcpy_s(arg1, _countof(arg1), arg2)
41 #define strncpy(arg1, arg2, arg3) \
42 strncpy_s(arg1, arg3, arg2, arg3)
43 #define sprintf(arg1, ...) \
44 sprintf_s(arg1, sizeof(arg1), __VA_ARGS__)
45 #endif
46
47#endif /* _WIN32 */
48
49#endif /* POSIX_OVERWRITES_H */