SYSENTER/SYSCALL support
[minix.git] / commands / uname / uname.c
blob9ed933168a919e8b1383e17977feae73ebd695a0
1 /* uname - print system name Author: Earl Chew */
3 /* Print the following system information as returned by the uname()
4 * function:
6 * system name Minix
7 * node name waddles
8 * release name 1.5
9 * version 10
10 * machine name i86
11 * arch i86 (Minix specific)
14 #include <sys/types.h>
15 #include <sys/utsname.h>
16 #include <stdarg.h>
17 #include <stdlib.h>
18 #include <string.h>
19 #include <unistd.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, ... );
31 void usage(void );
33 #ifdef __STDC__
34 void print(int fd, ...)
35 #else
36 void print(fd)
37 int fd;
38 #endif
40 /* Print a sequence of strings onto the named channel. */
41 va_list argp;
42 char *p;
44 va_start(argp, fd);
45 while (1) {
46 p = va_arg(argp, char *);
47 if (p == (char *) NULL) break;
48 write(fd, p, strlen(p));
50 va_end(argp);
53 char *name;
55 void usage()
57 print(STDERR_FILENO, "Usage: ", name, " -snrvmpa\n", (char *) NULL);
58 exit(EXIT_FAILURE);
61 int main(argc, argv)
62 int argc;
63 char **argv;
65 int info;
66 char *p;
67 struct utsname un;
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++) {
75 switch (*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;
83 default: usage();
86 } else {
87 usage();
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);
95 exit(EXIT_FAILURE);
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);
123 return EXIT_SUCCESS;