1 /* vi: set sw=4 ts=4: */
2 /* uname -- print system information
3 Copyright (C) 1989-1999 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software Foundation,
17 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
26 -a, --all SunOS rocky8 4.0 sun
28 The default behavior is equivalent to `-s'.
30 David MacKenzie <djm@gnu.ai.mit.edu> */
32 /* Busyboxed by Erik Andersen */
37 #include <sys/types.h>
38 #include <sys/utsname.h>
40 #if defined (HAVE_SYSINFO) && defined (HAVE_SYS_SYSTEMINFO_H)
41 # include <sys/systeminfo.h>
45 static void print_element(unsigned int mask, char *element);
47 /* Values that are bitwise or'd into `toprint'. */
48 /* Operating system name. */
49 static const int PRINT_SYSNAME = 1;
51 /* Node name on a communications network. */
52 static const int PRINT_NODENAME = 2;
54 /* Operating system release. */
55 static const int PRINT_RELEASE = 4;
57 /* Operating system version. */
58 static const int PRINT_VERSION = 8;
60 /* Machine hardware name. */
61 static const int PRINT_MACHINE = 16;
63 /* Host processor type. */
64 static const int PRINT_PROCESSOR = 32;
66 /* Mask indicating which elements of the name to print. */
67 static unsigned char toprint;
70 int uname_main(int argc, char **argv)
75 #if defined(__sparc__) && defined(__linux__)
76 char *fake_sparc = getenv("FAKE_SPARC");
81 /* Parse any options */
82 //fprintf(stderr, "argc=%d, argv=%s\n", argc, *argv);
83 while (--argc > 0 && **(++argv) == '-') {
84 while (*(++(*argv))) {
87 toprint |= PRINT_SYSNAME;
90 toprint |= PRINT_NODENAME;
93 toprint |= PRINT_RELEASE;
96 toprint |= PRINT_VERSION;
99 toprint |= PRINT_MACHINE;
102 toprint |= PRINT_PROCESSOR;
105 toprint = (PRINT_SYSNAME | PRINT_NODENAME | PRINT_RELEASE |
106 PRINT_PROCESSOR | PRINT_VERSION |
116 toprint = PRINT_SYSNAME;
118 if (uname(&name) == -1)
119 perror_msg("cannot get system name");
121 #if defined (HAVE_SYSINFO) && defined (SI_ARCHITECTURE)
122 if (sysinfo(SI_ARCHITECTURE, processor, sizeof(processor)) == -1)
123 perror_msg("cannot get processor type");
127 strcpy(processor, "unknown");
130 #if defined(__sparc__) && defined(__linux__)
131 if (fake_sparc != NULL
132 && (fake_sparc[0] == 'y'
133 || fake_sparc[0] == 'Y')) strcpy(name.machine, "sparc");
136 print_element(PRINT_SYSNAME, name.sysname);
137 print_element(PRINT_NODENAME, name.nodename);
138 print_element(PRINT_RELEASE, name.release);
139 print_element(PRINT_VERSION, name.version);
140 print_element(PRINT_MACHINE, name.machine);
141 print_element(PRINT_PROCESSOR, processor);
146 /* If the name element set in MASK is selected for printing in `toprint',
147 print ELEMENT; then print a space unless it is the last element to
148 be printed, in which case print a newline. */
150 static void print_element(unsigned int mask, char *element)
152 if (toprint & mask) {
154 printf("%s%c", element, toprint ? ' ' : '\n');