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