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 */
36 #include <sys/types.h>
37 #include <sys/utsname.h>
39 #if defined (HAVE_SYSINFO) && defined (HAVE_SYS_SYSTEMINFO_H)
40 # include <sys/systeminfo.h>
44 static const char uname_usage[] =
45 "uname [OPTION]...\n\n"
46 "Print certain system information. With no OPTION, same as -s.\n\n"
48 "\t-a\tprint all information\n"
49 "\t-m\tthe machine (hardware) type\n"
50 "\t-n\tprint the machine's network node hostname\n"
51 "\t-r\tprint the operating system release\n"
52 "\t-s\tprint the operating system name\n"
54 "\t-p\tprint the host processor type\n"
55 "\t-v\tprint the operating system version\n";
58 static void print_element(unsigned int mask, char *element);
60 /* Values that are bitwise or'd into `toprint'. */
61 /* Operating system name. */
62 #define PRINT_SYSNAME 1
64 /* Node name on a communications network. */
65 #define PRINT_NODENAME 2
67 /* Operating system release. */
68 #define PRINT_RELEASE 4
70 /* Operating system version. */
71 #define PRINT_VERSION 8
73 /* Machine hardware name. */
74 #define PRINT_MACHINE 16
76 /* Host processor type. */
77 #define PRINT_PROCESSOR 32
79 /* Mask indicating which elements of the name to print. */
80 static unsigned char toprint;
83 int uname_main(int argc, char **argv)
88 #if defined(__sparc__) && defined(__linux__)
89 char *fake_sparc = getenv("FAKE_SPARC");
94 /* Parse any options */
95 //fprintf(stderr, "argc=%d, argv=%s\n", argc, *argv);
96 while (--argc > 0 && **(++argv) == '-') {
97 while (*(++(*argv))) {
100 toprint |= PRINT_SYSNAME;
103 toprint |= PRINT_NODENAME;
106 toprint |= PRINT_RELEASE;
109 toprint |= PRINT_VERSION;
112 toprint |= PRINT_MACHINE;
115 toprint |= PRINT_PROCESSOR;
118 toprint = (PRINT_SYSNAME | PRINT_NODENAME | PRINT_RELEASE |
119 PRINT_PROCESSOR | PRINT_VERSION |
129 toprint = PRINT_SYSNAME;
131 if (uname(&name) == -1)
132 perror("cannot get system name");
134 #if defined (HAVE_SYSINFO) && defined (SI_ARCHITECTURE)
135 if (sysinfo(SI_ARCHITECTURE, processor, sizeof(processor)) == -1)
136 perror("cannot get processor type");
140 strcpy(processor, "unknown");
143 #if defined(__sparc__) && defined(__linux__)
144 if (fake_sparc != NULL
145 && (fake_sparc[0] == 'y'
146 || fake_sparc[0] == 'Y')) strcpy(name.machine, "sparc");
149 print_element(PRINT_SYSNAME, name.sysname);
150 print_element(PRINT_NODENAME, name.nodename);
151 print_element(PRINT_RELEASE, name.release);
152 print_element(PRINT_VERSION, name.version);
153 print_element(PRINT_MACHINE, name.machine);
154 print_element(PRINT_PROCESSOR, processor);
159 /* If the name element set in MASK is selected for printing in `toprint',
160 print ELEMENT; then print a space unless it is the last element to
161 be printed, in which case print a newline. */
163 static void print_element(unsigned int mask, char *element)
165 if (toprint & mask) {
167 printf("%s%c", element, toprint ? ' ' : '\n');