1 /* uname -- print system information
2 Copyright (C) 1989, 1991 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
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, 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> */
32 #if defined (CONFIG_BROKETS)
33 /* We use <config.h> instead of "config.h" so that a compilation
34 using -I. -I$srcdir will use ./config.h rather than $srcdir/config.h
35 (which it would do because it found this file in $srcdir). */
43 #include <sys/types.h>
44 #include <sys/utsname.h>
52 static void print_element ();
55 /* Values that are bitwise or'd into `toprint'. */
56 /* Operating system name. */
57 #define PRINT_SYSNAME 1
59 /* Node name on a communications network. */
60 #define PRINT_NODENAME 2
62 /* Operating system release. */
63 #define PRINT_RELEASE 4
65 /* Operating system version. */
66 #define PRINT_VERSION 8
68 /* Machine hardware name. */
69 #define PRINT_MACHINE 16
71 /* Mask indicating which elements of the name to print. */
72 static unsigned char toprint;
74 /* The name this program was run with, for error messages. */
77 /* If non-zero, display usage information and exit. */
80 /* If non-zero, print the version on standard output and exit. */
81 static int show_version;
83 static struct option const long_options[] =
85 {"help", no_argument, &show_help, 1},
86 {"machine", no_argument, NULL, 'm'},
87 {"nodename", no_argument, NULL, 'n'},
88 {"release", no_argument, NULL, 'r'},
89 {"sysname", no_argument, NULL, 's'},
90 {"version", no_argument, &show_version, 1},
91 {"all", no_argument, NULL, 'a'},
103 program_name = argv[0];
106 while ((c = getopt_long (argc, argv, "snrvma", long_options, (int *) 0))
115 toprint |= PRINT_SYSNAME;
119 toprint |= PRINT_NODENAME;
123 toprint |= PRINT_RELEASE;
127 toprint |= PRINT_VERSION;
131 toprint |= PRINT_MACHINE;
135 toprint = PRINT_SYSNAME | PRINT_NODENAME | PRINT_RELEASE |
136 PRINT_VERSION | PRINT_MACHINE;
146 printf ("%s\n", version_string);
157 toprint = PRINT_SYSNAME;
159 if (uname (&name) == -1)
160 error (1, errno, "cannot get system name");
162 print_element (PRINT_SYSNAME, name.sysname);
163 print_element (PRINT_NODENAME, name.nodename);
164 print_element (PRINT_RELEASE, name.release);
165 print_element (PRINT_VERSION, name.version);
166 print_element (PRINT_MACHINE, name.machine);
171 /* If the name element set in MASK is selected for printing in `toprint',
172 print ELEMENT; then print a space unless it is the last element to
173 be printed, in which case print a newline. */
176 print_element (mask, element)
183 printf ("%s%c", element, toprint ? ' ' : '\n');
191 fprintf (status == 0 ? stdout : stderr, "\
192 Usage: %s [OPTION]...\n\
197 fprintf (stderr, "Try `%s --help' for more information.\n",
203 -a, --all print all information\n\
204 -m, --machine print the machine (hardware) type\n\
205 -n, --nodename print the machine's network node hostname\n\
206 -r, --release print the operating system release\n\
207 -s, --sysname print the operating system name\n\
208 -v print the operating system version\n\
209 --help display this help and exit\n\
210 --version output version information and exit\n\
212 Without any OPTION, assume -s.\n\