1 /* uname -- print system information
2 Copyright (C) 89, 90, 91, 92, 93, 94, 1995 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> */
33 #include <sys/types.h>
34 #include <sys/utsname.h>
41 static void print_element ();
44 /* Values that are bitwise or'd into `toprint'. */
45 /* Operating system name. */
46 #define PRINT_SYSNAME 1
48 /* Node name on a communications network. */
49 #define PRINT_NODENAME 2
51 /* Operating system release. */
52 #define PRINT_RELEASE 4
54 /* Operating system version. */
55 #define PRINT_VERSION 8
57 /* Machine hardware name. */
58 #define PRINT_MACHINE 16
60 /* Mask indicating which elements of the name to print. */
61 static unsigned char toprint;
63 /* The name this program was run with, for error messages. */
66 /* If non-zero, display usage information and exit. */
69 /* If non-zero, print the version on standard output and exit. */
70 static int show_version;
72 static struct option const long_options[] =
74 {"help", no_argument, &show_help, 1},
75 {"machine", no_argument, NULL, 'm'},
76 {"nodename", no_argument, NULL, 'n'},
77 {"release", no_argument, NULL, 'r'},
78 {"sysname", no_argument, NULL, 's'},
79 {"version", no_argument, &show_version, 1},
80 {"all", no_argument, NULL, 'a'},
92 program_name = argv[0];
95 while ((c = getopt_long (argc, argv, "snrvma", long_options, (int *) 0))
104 toprint |= PRINT_SYSNAME;
108 toprint |= PRINT_NODENAME;
112 toprint |= PRINT_RELEASE;
116 toprint |= PRINT_VERSION;
120 toprint |= PRINT_MACHINE;
124 toprint = PRINT_SYSNAME | PRINT_NODENAME | PRINT_RELEASE |
125 PRINT_VERSION | PRINT_MACHINE;
135 printf ("uname - %s\n", version_string);
146 toprint = PRINT_SYSNAME;
148 if (uname (&name) == -1)
149 error (1, errno, "cannot get system name");
151 print_element (PRINT_SYSNAME, name.sysname);
152 print_element (PRINT_NODENAME, name.nodename);
153 print_element (PRINT_RELEASE, name.release);
154 print_element (PRINT_VERSION, name.version);
155 print_element (PRINT_MACHINE, name.machine);
160 /* If the name element set in MASK is selected for printing in `toprint',
161 print ELEMENT; then print a space unless it is the last element to
162 be printed, in which case print a newline. */
165 print_element (mask, element)
172 printf ("%s%c", element, toprint ? ' ' : '\n');
181 fprintf (stderr, "Try `%s --help' for more information.\n",
185 printf ("Usage: %s [OPTION]...\n", program_name);
188 -a, --all print all information\n\
189 -m, --machine print the machine (hardware) type\n\
190 -n, --nodename print the machine's network node hostname\n\
191 -r, --release print the operating system release\n\
192 -s, --sysname print the operating system name\n\
193 -v print the operating system version\n\
194 --help display this help and exit\n\
195 --version output version information and exit\n\
197 Without any OPTION, assume -s.\n\