-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.cpp
151 lines (103 loc) · 3.31 KB
/
main.cpp
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
#include <iostream>
// /Library/Developer/CommandLineTools/usr/include/c++/v1/iostream
// #include <filesystem>
#include <cstring>
// #include <dirent.h> // Allows the opening and listing of directories
// /Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include/dirent.h
// #include <unistd.h> // Various essential POSIX functions and constants
// /Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include/unistd.h
// #include <sys/types.h> // Various data types used elsewhere
// /Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include/sys/types.h
#include <sys/stat.h> // File information (stat et al.)
// /Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include/sys/stat.h
#include <errno.h>
using namespace std;
void test_posix() {
// $ mkdir test
// $ stat test
// drwxr-xr-x
int status = mkdir("test/b/c", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
std::cout << "status = " << status << std::endl;
if (0 != status) {
int errnum = errno;
std::cerr << "Ошибка при создании папки:\n\t" << strerror(errnum) << std::endl;
switch (errnum) {
case EEXIST:
std::cerr << "\tПапка уже сущетвует!" << std::endl;
break;
}
}
// Для пути a/b/c выдаст:
// status = -1
// Ошибка при создании папки:
// No such file or directory
// Вывод: mkdir не может создавать промежуточные папки.
// Для пути просто test создаст папку:
// $ stat test
// drwxr-xr-x
}
void check_os() {
std::cout << "OS:" << std::endl;
#ifdef __linux__
std::cout << "\tLinux and Linux-derived" << std::endl;
#endif
#ifdef __ANDROID__
std::cout << "\tAndroid (заключает в себе __linux__)" << std::endl;
#endif
#if defined(__linux__) && !defined(__ANDROID__)
std::cout << "\tLinux (non-Android)" << std::endl;
#endif
#ifdef __APPLE__
std::cout << "\tDarwin (Mac OS X and iOS)" << std::endl;
#endif
#ifdef __ros__
std::cout << "\tAkaros (http://akaros.org)" << std::endl;
#endif
#ifdef _WIN64
std::cout << "\tWindows 64 bit (заключает в себе _WIN32)" << std::endl;
#endif
#ifdef _WIN32
std::cout << "\tWindows" << std::endl;
#endif
#ifdef __native_client__
std::cout << "\tNaCL" << std::endl;
#endif
#ifdef __asmjs__
std::cout << "\tAsmJS" << std::endl;
#endif
#ifdef __Fuchsia__
std::cout << "\tFuschia" << std::endl;
#endif
}
void check_compiler() {
std::cout << "Compiler:" << std::endl;
#ifdef _MSC_VER
std::cout << "\tVisual Studio" << std::endl;
#endif
#ifdef __clang__
std::cout << "\tclang" << std::endl;
#endif
#ifdef __GNUC__
std::cout << "\tgcc" << std::endl;
#endif
#ifdef __EMSCRIPTEN__
std::cout << "\temscripten (for asm.js and webassembly)" << std::endl;
#endif
#ifdef __MINGW32__
std::cout << "\tMinGW 32 или MinGW-w64 32bit" << std::endl;
#endif
#ifdef __MINGW64__
std::cout << "\tMinGW-w64 64bit" << std::endl;
#endif
}
int main(int argc, char* argv[]) {
check_os();
// OS:
// Darwin (Mac OS X and iOS)
check_compiler();
// Compiler:
// clang
// gcc
test_posix();
return 0;
}