Make sure that input file name and output file name are distinct (to the extent possi...
[slunkcrypt.git] / frontend / src / platform.h
blobacd0b4bf298c8a6f2b232cb017aba06f1d6a4513
1 /******************************************************************************/
2 /* SlunkCrypt, by LoRd_MuldeR <MuldeR2@GMX.de> */
3 /* This work has been released under the CC0 1.0 Universal license! */
4 /******************************************************************************/
6 #ifndef INC_PLATFORM_H
7 #define INC_PLATFORM_H
9 #include <stdlib.h>
10 #include <stdio.h>
11 #include <string.h>
12 #ifdef _WIN32
13 # include <share.h>
14 # ifndef _SH_SECURE
15 # define _SH_SECURE 0x80
16 # endif
17 #endif
19 #if defined(_WIN32)
20 # define OS_TYPE "Windows"
21 #elif defined(__CYGWIN__)
22 # define OS_TYPE "Cygwin"
23 #elif defined(__linux__)
24 # define OS_TYPE "Linux"
25 #elif defined(__FreeBSD__)
26 # define OS_TYPE "FreeBSD"
27 #elif defined(__NetBSD__)
28 # define OS_TYPE "NetBSD"
29 #elif defined(__OpenBSD__)
30 # define OS_TYPE "OpenBSD"
31 #elif defined(__sun)
32 # define OS_TYPE "Solaris"
33 #elif defined(__unix__)
34 # define OS_TYPE "Unix"
35 #else
36 # error Unknown operating system!
37 #endif
39 #if defined(__x86_64__) || defined(_M_X64)
40 # define CPU_ARCH "x64"
41 #elif defined(__i386__) || defined(_M_IX86)
42 # define CPU_ARCH "x86"
43 #elif defined(__aarch64__) || defined(_M_ARM64)
44 # define CPU_ARCH "arm64"
45 #elif defined(__arm__) || defined(_M_ARM)
46 # define CPU_ARCH "arm"
47 #else
48 # error Unknown CPU architecture!
49 #endif
51 #ifdef _WIN32
52 # define MAIN wmain
53 # define CHR wchar_t
54 # define _T(X) L##X
55 # define GETENV(X) _wgetenv((X))
56 # define STRLEN(X) wcslen((X))
57 # define STRICMP(X,Y) _wcsicmp((X),(Y))
58 # define STRNICMP(X,Y,Z) _wcsnicmp((X),(Y),(Z))
59 # define STRRCHR(X,Y) wcsrchr((X),(Y))
60 # define STRTOUL(X) wcstoul((X), NULL, 0)
61 # define STRDUP(X) _wcsdup((X))
62 # define FPUTS(X,Y) fputws((X),(Y))
63 # define FPRINTF(X,Y,...) fwprintf((X),(Y),__VA_ARGS__)
64 # define REMOVE(X) _wremove((X))
65 # define FOPEN(X,Y) _wfsopen((X),(Y),_SH_SECURE)
66 # ifdef __USE_MINGW_ANSI_STDIO
67 # define PRISTR "ls"
68 # define PRIstr "hs"
69 # define PRIwcs "ls"
70 # else
71 # define PRISTR "s"
72 # define PRIstr "S"
73 # define PRIwcs "s"
74 # endif
75 #else
76 # define MAIN main
77 # define CHR char
78 # define _T(X) X
79 # define GETENV(X) getenv((X))
80 # define STRLEN(X) strlen((X))
81 # define STRICMP(X,Y) strcasecmp((X),(Y))
82 # define STRNICMP(X,Y,Z) strncasecmp((X),(Y),(Z))
83 # define STRRCHR(X,Y) strrchr((X),(Y))
84 # define STRTOUL(X) strtoul((X), NULL, 0)
85 # define STRDUP(X) strdup((X))
86 # define FPUTS(X,Y) fputs((X),(Y))
87 # define FPRINTF(X,Y,...) fprintf((X),(Y),__VA_ARGS__)
88 # define REMOVE(X) remove((X))
89 # define FOPEN(X,Y) fopen((X),(Y))
90 # define PRISTR "s"
91 # define PRIstr "s"
92 # define PRIwcs "ls"
93 #endif
95 #define T(X) _T(X)
97 #ifdef _MSC_VER
98 # define strdup(X) _strdup((X))
99 #endif
101 #endif