aboutsummaryrefslogtreecommitdiff
path: root/uname.c
diff options
context:
space:
mode:
Diffstat (limited to 'uname.c')
-rw-r--r--uname.c139
1 files changed, 71 insertions, 68 deletions
diff --git a/uname.c b/uname.c
index 9083edb04..9a1cb808a 100644
--- a/uname.c
+++ b/uname.c
@@ -1,3 +1,4 @@
1/* vi: set sw=4 ts=4: */
1/* uname -- print system information 2/* uname -- print system information
2 Copyright (C) 1989-1999 Free Software Foundation, Inc. 3 Copyright (C) 1989-1999 Free Software Foundation, Inc.
3 4
@@ -41,16 +42,17 @@
41 42
42 43
43static const char uname_usage[] = 44static const char uname_usage[] =
44 "uname [OPTION]...\n\n" 45 "uname [OPTION]...\n\n"
45 "Print certain system information. With no OPTION, same as -s.\n\n" 46 "Print certain system information. With no OPTION, same as -s.\n\n"
46 "Options:\n" 47 "Options:\n"
47 "\t-a\tprint all information\n" 48 "\t-a\tprint all information\n"
48 "\t-m\tthe machine (hardware) type\n" 49 "\t-m\tthe machine (hardware) type\n"
49 "\t-n\tprint the machine's network node hostname\n" 50 "\t-n\tprint the machine's network node hostname\n"
50 "\t-r\tprint the operating system release\n" 51 "\t-r\tprint the operating system release\n"
51 "\t-s\tprint the operating system name\n" 52 "\t-s\tprint the operating system name\n"
52 "\t-p\tprint the host processor type\n" 53
53 "\t-v\tprint the operating system version\n"; 54 "\t-p\tprint the host processor type\n"
55 "\t-v\tprint the operating system version\n";
54 56
55 57
56static void print_element(unsigned int mask, char *element); 58static void print_element(unsigned int mask, char *element);
@@ -80,77 +82,78 @@ static unsigned char toprint;
80 82
81int uname_main(int argc, char **argv) 83int uname_main(int argc, char **argv)
82{ 84{
83 struct utsname name; 85 struct utsname name;
84 char processor[256]; 86 char processor[256];
87
85#if defined(__sparc__) && defined(__linux__) 88#if defined(__sparc__) && defined(__linux__)
86 char *fake_sparc = getenv("FAKE_SPARC"); 89 char *fake_sparc = getenv("FAKE_SPARC");
87#endif 90#endif
88 91
89 toprint = 0; 92 toprint = 0;
90 93
91 /* Parse any options */ 94 /* Parse any options */
92 //fprintf(stderr, "argc=%d, argv=%s\n", argc, *argv); 95 //fprintf(stderr, "argc=%d, argv=%s\n", argc, *argv);
93 while (--argc > 0 && **(++argv) == '-') { 96 while (--argc > 0 && **(++argv) == '-') {
94 while (*(++(*argv))) { 97 while (*(++(*argv))) {
95 switch (**argv) { 98 switch (**argv) {
96 case 's': 99 case 's':
97 toprint |= PRINT_SYSNAME; 100 toprint |= PRINT_SYSNAME;
98 break; 101 break;
99 case 'n': 102 case 'n':
100 toprint |= PRINT_NODENAME; 103 toprint |= PRINT_NODENAME;
101 break; 104 break;
102 case 'r': 105 case 'r':
103 toprint |= PRINT_RELEASE; 106 toprint |= PRINT_RELEASE;
104 break; 107 break;
105 case 'v': 108 case 'v':
106 toprint |= PRINT_VERSION; 109 toprint |= PRINT_VERSION;
107 break; 110 break;
108 case 'm': 111 case 'm':
109 toprint |= PRINT_MACHINE; 112 toprint |= PRINT_MACHINE;
110 break; 113 break;
111 case 'p': 114 case 'p':
112 toprint |= PRINT_PROCESSOR; 115 toprint |= PRINT_PROCESSOR;
113 break; 116 break;
114 case 'a': 117 case 'a':
115 toprint = (PRINT_SYSNAME | PRINT_NODENAME | PRINT_RELEASE | 118 toprint = (PRINT_SYSNAME | PRINT_NODENAME | PRINT_RELEASE |
116 PRINT_PROCESSOR | PRINT_VERSION | 119 PRINT_PROCESSOR | PRINT_VERSION |
117 PRINT_MACHINE); 120 PRINT_MACHINE);
118 break; 121 break;
119 default: 122 default:
120 usage(uname_usage); 123 usage(uname_usage);
121 } 124 }
125 }
122 } 126 }
123 }
124 127
125 if (toprint == 0) 128 if (toprint == 0)
126 toprint = PRINT_SYSNAME; 129 toprint = PRINT_SYSNAME;
127 130
128 if (uname(&name) == -1) 131 if (uname(&name) == -1)
129 perror("cannot get system name"); 132 perror("cannot get system name");
130 133
131#if defined (HAVE_SYSINFO) && defined (SI_ARCHITECTURE) 134#if defined (HAVE_SYSINFO) && defined (SI_ARCHITECTURE)
132 if (sysinfo(SI_ARCHITECTURE, processor, sizeof(processor)) == -1) 135 if (sysinfo(SI_ARCHITECTURE, processor, sizeof(processor)) == -1)
133 perror("cannot get processor type"); 136 perror("cannot get processor type");
134} 137}
135 138
136#else 139#else
137 strcpy(processor, "unknown"); 140 strcpy(processor, "unknown");
138#endif 141#endif
139 142
140#if defined(__sparc__) && defined(__linux__) 143#if defined(__sparc__) && defined(__linux__)
141 if (fake_sparc != NULL 144 if (fake_sparc != NULL
142 && (fake_sparc[0] == 'y' 145 && (fake_sparc[0] == 'y'
143 || fake_sparc[0] == 'Y')) strcpy(name.machine, "sparc"); 146 || fake_sparc[0] == 'Y')) strcpy(name.machine, "sparc");
144#endif 147#endif
145 148
146 print_element(PRINT_SYSNAME, name.sysname); 149 print_element(PRINT_SYSNAME, name.sysname);
147 print_element(PRINT_NODENAME, name.nodename); 150 print_element(PRINT_NODENAME, name.nodename);
148 print_element(PRINT_RELEASE, name.release); 151 print_element(PRINT_RELEASE, name.release);
149 print_element(PRINT_VERSION, name.version); 152 print_element(PRINT_VERSION, name.version);
150 print_element(PRINT_MACHINE, name.machine); 153 print_element(PRINT_MACHINE, name.machine);
151 print_element(PRINT_PROCESSOR, processor); 154 print_element(PRINT_PROCESSOR, processor);
152 155
153 exit(TRUE); 156 exit(TRUE);
154} 157}
155 158
156/* If the name element set in MASK is selected for printing in `toprint', 159/* If the name element set in MASK is selected for printing in `toprint',
@@ -159,8 +162,8 @@ int uname_main(int argc, char **argv)
159 162
160static void print_element(unsigned int mask, char *element) 163static void print_element(unsigned int mask, char *element)
161{ 164{
162 if (toprint & mask) { 165 if (toprint & mask) {
163 toprint &= ~mask; 166 toprint &= ~mask;
164 printf("%s%c", element, toprint ? ' ' : '\n'); 167 printf("%s%c", element, toprint ? ' ' : '\n');
165 } 168 }
166} 169}