uname.c revision 1.2 1 /*
2 * uname - print system information. Jeff Comstock - Bloomington, MN USA 1992
3 * Usage: uname [-asnrvm]
4 * -s prints system name
5 * -n prints nodename
6 * -r prints software release
7 * -v prints os version
8 * -m prints machine name
9 * -a prinst all the above information
10 */
11
12 #ifndef lint
13 static char rcsid[] = "$Id: uname.c,v 1.2 1993/08/02 17:56:27 mycroft Exp $";
14 #endif /* not lint */
15
16 #include <stdio.h>
17 #include <unistd.h>
18 #include <sys/utsname.h>
19
20 #define SYSNAME 0
21 #define NODENAME 1
22 #define RELEASE 2
23 #define VERSION 3
24 #define MACHINE 4
25
26 struct utsname u;
27
28 struct utstab {
29 char *str;
30 int requested;
31 } uttab[] = {
32 { u.sysname, 0 },
33 { u.nodename, 0 },
34 { u.release, 0 },
35 { u.version, 0 },
36 { u.machine, 0 }
37 };
38
39 main(int argc, char **argv) {
40 char *opts="amnrsv";
41 register int c,space, all=0;
42
43 if ( ! uname(&u) ) {
44 if ( argc == 1 ) {
45 puts(u.sysname);
46 } else {
47 while ( (c = getopt(argc,argv,opts)) != -1 ) {
48 switch ( c ) {
49 case 'a' : all++;
50 break;
51 case 'm' : uttab[MACHINE].requested++;
52 break;
53 case 'n' : uttab[NODENAME].requested++;
54 break;
55 case 'r' : uttab[RELEASE].requested++;
56 break;
57 case 's' : uttab[SYSNAME].requested++;
58 break;
59 case 'v' : uttab[VERSION].requested++;
60 break;
61 }
62 }
63 space=0;
64 for(c=0; c <= MACHINE; c++) {
65 if ( uttab[c].requested || all ) {
66 if ( space )
67 putchar(' ');
68 printf("%s", uttab[c].str);
69 space++;
70 }
71 }
72 puts("");
73 }
74 }
75 else
76 perror("uname");
77 }
78