1 /* uname -- print system information
2 Copyright (C) 1989-1999 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software Foundation,
16 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
25 -a, --all SunOS rocky8 4.0 sun
27 The default behavior is equivalent to `-s'.
29 David MacKenzie <djm@gnu.ai.mit.edu> */
31 /* Busyboxed by Erik Andersen */
35 #include <sys/types.h>
36 #include <sys/utsname.h>
38 #if defined (HAVE_SYSINFO) && defined (HAVE_SYS_SYSTEMINFO_H)
39 # include <sys/systeminfo.h>
43 static const char uname_usage[] =
45 "Print certain system information. With no OPTION, same as -s.\n"
46 "\t-a\tprint all information\n"
47 "\t-m\tthe machine (hardware) type\n"
48 "\t-n\tprint the machine's network node hostname\n"
49 "\t-r\tprint the operating system release\n"
50 "\t-s\tprint the operating system name\n"
51 "\t-p\tprint the host processor type\n"
52 "\t-v\tprint the operating system version\n";
55 static void print_element(unsigned int mask, char *element);
57 /* Values that are bitwise or'd into `toprint'. */
58 /* Operating system name. */
59 #define PRINT_SYSNAME 1
61 /* Node name on a communications network. */
62 #define PRINT_NODENAME 2
64 /* Operating system release. */
65 #define PRINT_RELEASE 4
67 /* Operating system version. */
68 #define PRINT_VERSION 8
70 /* Machine hardware name. */
71 #define PRINT_MACHINE 16
73 /* Host processor type. */
74 #define PRINT_PROCESSOR 32
76 /* Mask indicating which elements of the name to print. */
77 static unsigned char toprint;
80 int uname_main(int argc, char **argv)
84 #if defined(__sparc__) && defined(__linux__)
85 char *fake_sparc = getenv("FAKE_SPARC");
90 /* Parse any options */
91 //fprintf(stderr, "argc=%d, argv=%s\n", argc, *argv);
92 while (--argc > 0 && **(++argv) == '-') {
93 while (*(++(*argv))) {
96 toprint |= PRINT_SYSNAME;
99 toprint |= PRINT_NODENAME;
102 toprint |= PRINT_RELEASE;
105 toprint |= PRINT_VERSION;
108 toprint |= PRINT_MACHINE;
111 toprint |= PRINT_PROCESSOR;
114 toprint = (PRINT_SYSNAME | PRINT_NODENAME | PRINT_RELEASE |
115 PRINT_PROCESSOR | PRINT_VERSION |
125 toprint = PRINT_SYSNAME;
127 if (uname(&name) == -1)
128 perror("cannot get system name");
130 #if defined (HAVE_SYSINFO) && defined (SI_ARCHITECTURE)
131 if (sysinfo(SI_ARCHITECTURE, processor, sizeof(processor)) == -1)
132 perror("cannot get processor type");
136 strcpy(processor, "unknown");
139 #if defined(__sparc__) && defined(__linux__)
140 if (fake_sparc != NULL
141 && (fake_sparc[0] == 'y'
142 || fake_sparc[0] == 'Y')) strcpy(name.machine, "sparc");
145 print_element(PRINT_SYSNAME, name.sysname);
146 print_element(PRINT_NODENAME, name.nodename);
147 print_element(PRINT_RELEASE, name.release);
148 print_element(PRINT_VERSION, name.version);
149 print_element(PRINT_MACHINE, name.machine);
150 print_element(PRINT_PROCESSOR, processor);
155 /* If the name element set in MASK is selected for printing in `toprint',
156 print ELEMENT; then print a space unless it is the last element to
157 be printed, in which case print a newline. */
159 static void print_element(unsigned int mask, char *element)
161 if (toprint & mask) {
163 printf("%s%c", element, toprint ? ' ' : '\n');