1 /* vi: set sw=4 ts=4: */
2 /* uname -- print system information
3 * Copyright (C) 1989-1999 Free Software Foundation, Inc.
5 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
8 /* BB_AUDIT SUSv3 compliant */
9 /* http://www.opengroup.org/onlinepubs/007904975/utilities/uname.html */
13 * -n, --nodename rocky8
17 * -a, --all SunOS rocky8 4.0 sun
19 * The default behavior is equivalent to '-s'.
21 * David MacKenzie <djm@gnu.ai.mit.edu>
24 * Option: struct Example(s):
27 * -s, --kernel-name sysname Linux
28 * -n, --nodename nodename localhost.localdomain
29 * -r, --kernel-release release 2.6.29
30 * -v, --kernel-version version #1 SMP Sun Jan 11 20:52:37 EST 2009
31 * -m, --machine machine x86_64 i686
32 * -p, --processor (none) x86_64 i686
33 * -i, --hardware-platform (none) x86_64 i386
34 * NB: vanilla coreutils reports "unknown" -p and -i,
35 * x86_64 and i686/i386 shown above are Fedora's inventions.
36 * -o, --operating-system (none) GNU/Linux
37 * -a, --all: all of the above, in the order shown.
38 * If -p or -i is not known, don't show them
41 /* Busyboxed by Erik Andersen
43 * Before 2003: Glenn McGrath and Manuel Novoa III
44 * Further size reductions.
45 * Mar 16, 2003: Manuel Novoa III (mjn3@codepoet.org)
46 * Now does proper error checking on i/o. Plus some further space savings.
48 * Fix handling of -a to not print "unknown", add -o and -i support.
51 #include <sys/utsname.h>
56 char processor[sizeof(((struct utsname*)NULL)->machine)];
57 char platform[sizeof(((struct utsname*)NULL)->machine)];
58 char os[sizeof("GNU/Linux")];
61 static const char options[] ALIGN1 = "snrvmpioa";
62 static const unsigned short utsname_offset[] = {
63 offsetof(uname_info_t, name.sysname), /* -s */
64 offsetof(uname_info_t, name.nodename), /* -n */
65 offsetof(uname_info_t, name.release), /* -r */
66 offsetof(uname_info_t, name.version), /* -v */
67 offsetof(uname_info_t, name.machine), /* -m */
68 offsetof(uname_info_t, processor), /* -p */
69 offsetof(uname_info_t, platform), /* -i */
70 offsetof(uname_info_t, os), /* -o */
73 int uname_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
74 int uname_main(int argc UNUSED_PARAM, char **argv)
76 #if ENABLE_GETOPT_LONG
77 static const char longopts[] ALIGN1 =
78 /* name, has_arg, val */
79 "all\0" No_argument "a"
80 "kernel-name\0" No_argument "s"
81 "nodename\0" No_argument "n"
82 "kernel-release\0" No_argument "r"
83 "release\0" No_argument "r"
84 "kernel-version\0" No_argument "v"
85 "machine\0" No_argument "m"
86 "processor\0" No_argument "p"
87 "hardware-platform\0" No_argument "i"
88 "operating-system\0" No_argument "o"
91 uname_info_t uname_info;
92 #if defined(__sparc__) && defined(__linux__)
93 char *fake_sparc = getenv("FAKE_SPARC");
95 const char *unknown_str = "unknown";
97 const unsigned short *delta;
100 IF_GETOPT_LONG(applet_long_options = longopts);
101 toprint = getopt32(argv, options);
103 if (argv[optind]) { /* coreutils-6.9 compat */
107 if (toprint & (1 << 8)) { /* -a => all opts on */
108 toprint = (1 << 8) - 1;
109 unknown_str = ""; /* -a does not print unknown fields */
112 if (toprint == 0) { /* no opts => -s (sysname) */
116 uname(&uname_info.name); /* never fails */
118 #if defined(__sparc__) && defined(__linux__)
119 if (fake_sparc && (fake_sparc[0] | 0x20) == 'y') {
120 strcpy(uname_info.name.machine, "sparc");
123 strcpy(uname_info.processor, unknown_str);
124 strcpy(uname_info.platform, unknown_str);
125 strcpy(uname_info.os, "GNU/Linux");
127 /* Fedora does something like this */
128 strcpy(uname_info.processor, uname_info.name.machine);
129 strcpy(uname_info.platform, uname_info.name.machine);
130 if (uname_info.platform[0] == 'i'
131 && uname_info.platform[1]
132 && uname_info.platform[2] == '8'
133 && uname_info.platform[3] == '6'
135 uname_info.platform[1] = '3';
139 delta = utsname_offset;
143 const char *p = (char *)(&uname_info) + *delta;
150 } while (toprint >>= 1);
153 fflush_stdout_and_exit(EXIT_SUCCESS); /* coreutils-6.9 compat */