blob: 64e43c3565d7fab4af7925230e50d855f041684a (
plain)
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
|
#include <stdio.h>
#include <sys/utsname.h>
int main(int argc, char** argv)
{
utsname uts;
int rc = uname(&uts);
if (rc < 0) {
perror("uname() failed");
return 0;
}
bool flag_s = false;
bool flag_n = false;
bool flag_r = false;
bool flag_m = false;
if (argc == 1) {
flag_s = true;
} else {
for (int i = 1; i < argc; ++i) {
if (argv[i][0] == '-') {
for (const char* o = &argv[i][1]; *o; ++o) {
switch (*o) {
case 's': flag_s = true; break;
case 'n': flag_n = true; break;
case 'r': flag_r = true; break;
case 'm': flag_m = true; break;
case 'a': flag_s = flag_n = flag_r = flag_m = true; break;
}
}
}
}
}
if (!flag_s && !flag_n && !flag_r && !flag_m)
flag_s = true;
if (flag_s)
printf("%s ", uts.sysname);
if (flag_n)
printf("%s ", uts.nodename);
if (flag_r)
printf("%s ", uts.release);
if (flag_m)
printf("%s ", uts.machine);
printf("\n");
return 0;
}
|