This commit was generated by cvs2svn to track changes on a CVS vendor
[unix-history] / usr.bin / uname / uname.c
CommitLineData
f1811a66
JH
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
b9269098 13static char rcsid[] = "$Id: uname.c,v 1.2 1994/01/24 02:14:26 rgrimes Exp $";
f1811a66
JH
14#endif /* not lint */
15
16#include <stdio.h>
17#include <unistd.h>
18#include <sysexits.h>
19#include <sys/utsname.h>
20
21#define SYSNAME 0
22#define NODENAME 1
23#define RELEASE 2
24#define VERSION 3
25#define MACHINE 4
26
27struct utsname u;
28
29struct utstab {
30 char *str;
31 int requested;
32} uttab[] = {
33 { u.sysname, 0 },
34 { u.nodename, 0 },
35 { u.release, 0 },
36 { u.version, 0 },
37 { u.machine, 0 }
38};
39
40main(int argc, char **argv) {
41char *opts="amnrsv";
42register int c,space, all=0;
43
44 if ( ! uname(&u) ) {
45 if ( argc == 1 ) {
b9269098 46 puts(u.sysname);
f1811a66
JH
47 } else {
48 while ( (c = getopt(argc,argv,opts)) != -1 ) {
49 switch ( c ) {
50 case 'a' : all++;
51 break;
52 case 'm' : uttab[MACHINE].requested++;
53 break;
54 case 'n' : uttab[NODENAME].requested++;
55 break;
56 case 'r' : uttab[RELEASE].requested++;
57 break;
58 case 's' : uttab[SYSNAME].requested++;
59 break;
60 case 'v' : uttab[VERSION].requested++;
61 break;
62 }
63 }
64 space=0;
65 for(c=0; c <= MACHINE; c++) {
66 if ( uttab[c].requested || all ) {
67 if ( space )
68 putchar(' ');
69 printf("%s", uttab[c].str);
70 space++;
71 }
72 }
73 puts("");
74 }
75 exit (EX_OK);
76 } else {
77 perror("uname");
78 exit (EX_OSERR);
79 }
80}