source: trunk/minix/commands/simple/uname.c@ 9

Last change on this file since 9 was 9, checked in by Mattia Monga, 13 years ago

Minix 3.1.2a

File size: 3.0 KB
Line 
1/* uname - print system name Author: Earl Chew */
2
3/* Print the following system information as returned by the uname()
4 * function:
5 *
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)
12 */
13
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>
20
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)
29
30_PROTOTYPE(int main, (int argc, char **argv ));
31_PROTOTYPE(void print, (int fd, ... ));
32_PROTOTYPE(void usage, (void ));
33
34#ifdef __STDC__
35void print(int fd, ...)
36#else
37void print(fd)
38int fd;
39#endif
40{
41/* Print a sequence of strings onto the named channel. */
42 va_list argp;
43 char *p;
44
45 va_start(argp, fd);
46 while (1) {
47 p = va_arg(argp, char *);
48 if (p == (char *) NULL) break;
49 write(fd, p, strlen(p));
50 }
51 va_end(argp);
52}
53
54char *name;
55
56void usage()
57{
58 print(STDERR_FILENO, "Usage: ", name, " -snrvmpa\n", (char *) NULL);
59 exit(EXIT_FAILURE);
60}
61
62int main(argc, argv)
63int argc;
64char **argv;
65{
66 int info;
67 char *p;
68 struct utsname un;
69
70 name = strrchr(argv[0], '/');
71 if (name == NULL) name = argv[0]; else name++;
72
73 for (info = 0; argc > 1; argc--, argv++) {
74 if (argv[1][0] == '-') {
75 for (p = &argv[1][1]; *p; p++) {
76 switch (*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;
84 default: usage();
85 }
86 }
87 } else {
88 usage();
89 }
90 }
91
92 if (info == 0) info = strcmp(name, "arch") == 0 ? ARCH : SYSNAME;
93
94 if (uname(&un) != 0) {
95 print(STDERR_FILENO, "unable to determine uname values\n", (char *) NULL);
96 exit(EXIT_FAILURE);
97 }
98
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);
105 }
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);
110 }
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);
115 }
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);
120 }
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);
125 }
126 print(STDOUT_FILENO, "\n", (char *) NULL);
127 return EXIT_SUCCESS;
128}
Note: See TracBrowser for help on using the repository browser.