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. */
19 /* BB_AUDIT SUSv3 compliant */
20 /* http://www.opengroup.org/onlinepubs/007904975/utilities/uname.html */
29 -a, --all SunOS rocky8 4.0 sun
31 The default behavior is equivalent to `-s'.
33 David MacKenzie <djm@gnu.ai.mit.edu> */
35 /* Busyboxed by Erik Andersen */
37 /* Further size reductions by Glenn McGrath and Manuel Novoa III. */
39 /* Mar 16, 2003 Manuel Novoa III (mjn3@codepoet.org)
41 * Now does proper error checking on i/o. Plus some further space savings.
49 #include <sys/types.h>
50 #include <sys/utsname.h>
55 char processor[8]; /* for "unknown" */
58 static const char options[] = "snrvmpa";
59 static const unsigned short int utsname_offset[] = {
60 offsetof(uname_info_t,name.sysname),
61 offsetof(uname_info_t,name.nodename),
62 offsetof(uname_info_t,name.release),
63 offsetof(uname_info_t,name.version),
64 offsetof(uname_info_t,name.machine),
65 offsetof(uname_info_t,processor)
68 int uname_main(int argc, char **argv)
70 uname_info_t uname_info;
71 #if defined(__sparc__) && defined(__linux__)
72 char *fake_sparc = getenv("FAKE_SPARC");
74 const unsigned short int *delta;
77 toprint = bb_getopt_ulflags(argc, argv, options);
83 if (toprint & (1 << 6)) {
88 toprint = 1; /* sysname */
91 if (uname(&uname_info.name) == -1) {
92 bb_error_msg_and_die("cannot get system name");
95 #if defined(__sparc__) && defined(__linux__)
96 if ((fake_sparc != NULL)
97 && ((fake_sparc[0] == 'y')
98 || (fake_sparc[0] == 'Y'))) {
99 strcpy(uname_info.name.machine, "sparc");
103 strcpy(uname_info.processor, "unknown");
105 delta=utsname_offset;
108 bb_printf(((char *)(&uname_info)) + *delta);
114 } while (toprint >>= 1);
117 bb_fflush_stdout_and_exit(EXIT_SUCCESS);