1 /* uname - print system name Author: Earl Chew */
3 /* Print the following system information as returned by the uname()
11 * arch i86 (Minix specific)
14 #include <sys/types.h>
15 #include <sys/utsname.h>
21 /* Define the uname components. */
22 #define ALL ((unsigned) 0x1F)
23 #define SYSNAME ((unsigned) 0x01)
24 #define NODENAME ((unsigned) 0x02)
25 #define RELEASE ((unsigned) 0x04)
26 #define VERSION ((unsigned) 0x08)
27 #define U_MACHINE ((unsigned) 0x10)
28 #define ARCH ((unsigned) 0x20)
30 _PROTOTYPE(int main
, (int argc
, char **argv
));
31 _PROTOTYPE(void print
, (int fd
, ... ));
32 _PROTOTYPE(void usage
, (void ));
35 void print(int fd
, ...)
41 /* Print a sequence of strings onto the named channel. */
47 p
= va_arg(argp
, char *);
48 if (p
== (char *) NULL
) break;
49 write(fd
, p
, strlen(p
));
58 print(STDERR_FILENO
, "Usage: ", name
, " -snrvmpa\n", (char *) NULL
);
70 name
= strrchr(argv
[0], '/');
71 if (name
== NULL
) name
= argv
[0]; else name
++;
73 for (info
= 0; argc
> 1; argc
--, argv
++) {
74 if (argv
[1][0] == '-') {
75 for (p
= &argv
[1][1]; *p
; p
++) {
77 case 'a': info
|= ALL
; break;
78 case 'm': info
|= U_MACHINE
; break;
79 case 'n': info
|= NODENAME
; break;
80 case 'r': info
|= RELEASE
; break;
81 case 's': info
|= SYSNAME
; break;
82 case 'v': info
|= VERSION
; break;
83 case 'p': info
|= ARCH
; break;
92 if (info
== 0) info
= strcmp(name
, "arch") == 0 ? ARCH
: SYSNAME
;
94 if (uname(&un
) != 0) {
95 print(STDERR_FILENO
, "unable to determine uname values\n", (char *) NULL
);
99 if ((info
& SYSNAME
) != 0)
100 print(STDOUT_FILENO
, un
.sysname
, (char *) NULL
);
101 if ((info
& NODENAME
) != 0) {
102 if ((info
& (SYSNAME
)) != 0)
103 print(STDOUT_FILENO
, " ", (char *) NULL
);
104 print(STDOUT_FILENO
, un
.nodename
, (char *) NULL
);
106 if ((info
& RELEASE
) != 0) {
107 if ((info
& (SYSNAME
|NODENAME
)) != 0)
108 print(STDOUT_FILENO
, " ", (char *) NULL
);
109 print(STDOUT_FILENO
, un
.release
, (char *) NULL
);
111 if ((info
& VERSION
) != 0) {
112 if ((info
& (SYSNAME
|NODENAME
|RELEASE
)) != 0)
113 print(STDOUT_FILENO
, " ", (char *) NULL
);
114 print(STDOUT_FILENO
, un
.version
, (char *) NULL
);
116 if ((info
& U_MACHINE
) != 0) {
117 if ((info
& (SYSNAME
|NODENAME
|RELEASE
|VERSION
)) != 0)
118 print(STDOUT_FILENO
, " ", (char *) NULL
);
119 print(STDOUT_FILENO
, un
.machine
, (char *) NULL
);
121 if ((info
& ARCH
) != 0) {
122 if ((info
& (SYSNAME
|NODENAME
|RELEASE
|VERSION
|U_MACHINE
)) != 0)
123 print(STDOUT_FILENO
, " ", (char *) NULL
);
124 print(STDOUT_FILENO
, un
.arch
, (char *) NULL
);
126 print(STDOUT_FILENO
, "\n", (char *) NULL
);