-
Notifications
You must be signed in to change notification settings - Fork 2
/
uname.c
58 lines (55 loc) · 1006 Bytes
/
uname.c
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
/* See LICENSE file for copyright and license details. */
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/utsname.h>
#include "util.h"
int
main(int argc, char *argv[])
{
bool mflag = false;
bool nflag = false;
bool rflag = false;
bool sflag = false;
bool vflag = false;
char c;
struct utsname u;
while((c = getopt(argc, argv, "amnrsv")) != -1)
switch(c) {
case 'a':
mflag = nflag = rflag = sflag = vflag = true;
break;
case 'm':
mflag = true;
break;
case 'n':
nflag = true;
break;
case 'r':
rflag = true;
break;
case 's':
sflag = true;
break;
case 'v':
vflag = true;
break;
default:
exit(EXIT_FAILURE);
}
if(uname(&u) == -1)
eprintf("uname:");
if(sflag || !(nflag || rflag || vflag || mflag))
putword(u.sysname);
if(nflag)
putword(u.nodename);
if(rflag)
putword(u.release);
if(vflag)
putword(u.version);
if(mflag)
putword(u.machine);
putchar('\n');
return EXIT_SUCCESS;
}