Added new option to generate a random passphrase.
[slunkcrypt.git] / frontend / src / platform.h
blob73596e8c0703199fadf00c29ec8f1dc9db5fb859
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 STRRCHR(X,Y) wcsrchr((X),(Y))
59 # define STRTOUL(X) wcstoul((X), NULL, 0)
60 # define FPUTS(X,Y) fputws((X),(Y))
61 # define FPRINTF(X,Y,...) fwprintf((X),(Y),__VA_ARGS__)
62 # define FOPEN(X,Y) _wfsopen((X),(Y),_SH_SECURE)
63 # ifdef __USE_MINGW_ANSI_STDIO
64 # define PRISTR "ls"
65 # define PRIstr "hs"
66 # define PRIwcs "ls"
67 # else
68 # define PRISTR "s"
69 # define PRIstr "S"
70 # define PRIwcs "s"
71 # endif
72 #else
73 # define MAIN main
74 # define CHR char
75 # define _T(X) X
76 # define GETENV(X) getenv((X))
77 # define STRLEN(X) strlen((X))
78 # define STRICMP(X,Y) strcasecmp((X),(Y))
79 # define STRRCHR(X,Y) strrchr((X),(Y))
80 # define STRTOUL(X) strtoul((X), NULL, 0)
81 # define FPUTS(X,Y) fputs((X),(Y))
82 # define FPRINTF(X,Y,...) fprintf((X),(Y),__VA_ARGS__)
83 # define FOPEN(X,Y) fopen((X),(Y))
84 # define PRISTR "s"
85 # define PRIstr "s"
86 # define PRIwcs "ls"
87 #endif
89 #define T(X) _T(X)
91 #ifdef _MSC_VER
92 # define strdup(X) _strdup((X))
93 #endif
95 #endif