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>
40 static void print_element
__P ((unsigned int mask
, char *element
));
41 static void usage
__P ((int status
));
43 /* Values that are bitwise or'd into `toprint'. */
44 /* Operating system name. */
45 #define PRINT_SYSNAME 1
47 /* Node name on a communications network. */
48 #define PRINT_NODENAME 2
50 /* Operating system release. */
51 #define PRINT_RELEASE 4
53 /* Operating system version. */
54 #define PRINT_VERSION 8
56 /* Machine hardware name. */
57 #define PRINT_MACHINE 16
59 /* Mask indicating which elements of the name to print. */
60 static unsigned char toprint
;
62 /* The name this program was run with, for error messages. */
65 /* If nonzero, display usage information and exit. */
68 /* If nonzero, print the version on standard output and exit. */
69 static int show_version
;
71 static struct option
const long_options
[] =
73 {"help", no_argument
, &show_help
, 1},
74 {"machine", no_argument
, NULL
, 'm'},
75 {"nodename", no_argument
, NULL
, 'n'},
76 {"release", no_argument
, NULL
, 'r'},
77 {"sysname", no_argument
, NULL
, 's'},
78 {"version", no_argument
, &show_version
, 1},
79 {"all", no_argument
, NULL
, 'a'},
84 main (int argc
, char **argv
)
89 program_name
= argv
[0];
90 setlocale (LC_ALL
, "");
91 bindtextdomain (PACKAGE
, LOCALEDIR
);
96 while ((c
= getopt_long (argc
, argv
, "snrvma", long_options
, (int *) 0))
105 toprint
|= PRINT_SYSNAME
;
109 toprint
|= PRINT_NODENAME
;
113 toprint
|= PRINT_RELEASE
;
117 toprint
|= PRINT_VERSION
;
121 toprint
|= PRINT_MACHINE
;
125 toprint
= PRINT_SYSNAME
| PRINT_NODENAME
| PRINT_RELEASE
|
126 PRINT_VERSION
| PRINT_MACHINE
;
136 printf ("uname - %s\n", PACKAGE_VERSION
);
147 toprint
= PRINT_SYSNAME
;
149 if (uname (&name
) == -1)
150 error (1, errno
, _("cannot get system name"));
152 print_element (PRINT_SYSNAME
, name
.sysname
);
153 print_element (PRINT_NODENAME
, name
.nodename
);
154 print_element (PRINT_RELEASE
, name
.release
);
155 print_element (PRINT_VERSION
, name
.version
);
156 print_element (PRINT_MACHINE
, name
.machine
);
161 /* If the name element set in MASK is selected for printing in `toprint',
162 print ELEMENT; then print a space unless it is the last element to
163 be printed, in which case print a newline. */
166 print_element (unsigned int mask
, char *element
)
171 printf ("%s%c", element
, toprint
? ' ' : '\n');
179 fprintf (stderr
, _("Try `%s --help' for more information.\n"),
183 printf (_("Usage: %s [OPTION]...\n"), program_name
);
185 Print certain system information. With no OPTION, same as -s.\n\
187 -a, --all print all information\n\
188 -m, --machine print the machine (hardware) type\n\
189 -n, --nodename print the machine's network node hostname\n\
190 -r, --release print the operating system release\n\
191 -s, --sysname print the operating system name\n\
192 -v print the operating system version\n\
193 --help display this help and exit\n\
194 --version output version information and exit\n"));