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 U_MACHINE ((unsigned) 0x10)
27 #define ARCH ((unsigned) 0x20)
29 int main(int argc
, char **argv
);
30 void print(int fd
, ... );
34 void print(int fd
, ...)
40 /* Print a sequence of strings onto the named channel. */
46 p
= va_arg(argp
, char *);
47 if (p
== (char *) NULL
) break;
48 write(fd
, p
, strlen(p
));
57 print(STDERR_FILENO
, "Usage: ", name
, " -snrvmpa\n", (char *) NULL
);
69 name
= strrchr(argv
[0], '/');
70 if (name
== NULL
) name
= argv
[0]; else name
++;
72 for (info
= 0; argc
> 1; argc
--, argv
++) {
73 if (argv
[1][0] == '-') {
74 for (p
= &argv
[1][1]; *p
; p
++) {
76 case 'a': info
|= ALL
; break;
77 case 'm': info
|= U_MACHINE
; break;
78 case 'n': info
|= NODENAME
; break;
79 case 'r': info
|= RELEASE
; break;
80 case 's': info
|= SYSNAME
; break;
81 case 'v': info
|= RELEASE
; break;
82 case 'p': info
|= ARCH
; break;
91 if (info
== 0) info
= strcmp(name
, "arch") == 0 ? ARCH
: SYSNAME
;
93 if (uname(&un
) != 0) {
94 print(STDERR_FILENO
, "unable to determine uname values\n", (char *) NULL
);
98 if ((info
& SYSNAME
) != 0)
99 print(STDOUT_FILENO
, un
.sysname
, (char *) NULL
);
100 if ((info
& NODENAME
) != 0) {
101 if ((info
& (SYSNAME
)) != 0)
102 print(STDOUT_FILENO
, " ", (char *) NULL
);
103 print(STDOUT_FILENO
, un
.nodename
, (char *) NULL
);
105 if ((info
& RELEASE
) != 0) {
106 if ((info
& (SYSNAME
|NODENAME
)) != 0)
107 print(STDOUT_FILENO
, " ", (char *) NULL
);
108 print(STDOUT_FILENO
, un
.release
, (char *) NULL
);
109 print(STDOUT_FILENO
, ".", (char *) NULL
);
110 print(STDOUT_FILENO
, un
.version
, (char *) NULL
);
112 if ((info
& U_MACHINE
) != 0) {
113 if ((info
& (SYSNAME
|NODENAME
|RELEASE
)) != 0)
114 print(STDOUT_FILENO
, " ", (char *) NULL
);
115 print(STDOUT_FILENO
, un
.machine
, (char *) NULL
);
117 if ((info
& ARCH
) != 0) {
118 if ((info
& (SYSNAME
|NODENAME
|RELEASE
|U_MACHINE
)) != 0)
119 print(STDOUT_FILENO
, " ", (char *) NULL
);
120 print(STDOUT_FILENO
, un
.arch
, (char *) NULL
);
122 print(STDOUT_FILENO
, "\n", (char *) NULL
);