1 /* uname -- print system information
2 Copyright (C) 1989-1999 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 Foundation,
16 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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>
37 #if defined (HAVE_SYSINFO) && defined (HAVE_SYS_SYSTEMINFO_H)
38 # include <sys/systeminfo.h>
44 /* The official name of this program (e.g., no `g' prefix). */
45 #define PROGRAM_NAME "uname"
47 #define AUTHORS "David MacKenzie"
49 static void print_element
PARAMS ((unsigned int mask
, char *element
));
51 /* Values that are bitwise or'd into `toprint'. */
52 /* Operating system name. */
53 #define PRINT_SYSNAME 1
55 /* Node name on a communications network. */
56 #define PRINT_NODENAME 2
58 /* Operating system release. */
59 #define PRINT_RELEASE 4
61 /* Operating system version. */
62 #define PRINT_VERSION 8
64 /* Machine hardware name. */
65 #define PRINT_MACHINE 16
67 /* Host processor type. */
68 #define PRINT_PROCESSOR 32
70 /* Mask indicating which elements of the name to print. */
71 static unsigned char toprint
;
73 /* The name this program was run with, for error messages. */
76 static struct option
const long_options
[] =
78 {"machine", no_argument
, NULL
, 'm'},
79 {"nodename", no_argument
, NULL
, 'n'},
80 {"release", no_argument
, NULL
, 'r'},
81 {"sysname", no_argument
, NULL
, 's'},
82 {"processor", no_argument
, NULL
, 'p'},
83 {"all", no_argument
, NULL
, 'a'},
84 {GETOPT_HELP_OPTION_DECL
},
85 {GETOPT_VERSION_OPTION_DECL
},
93 fprintf (stderr
, _("Try `%s --help' for more information.\n"),
97 printf (_("Usage: %s [OPTION]...\n"), program_name
);
99 Print certain system information. With no OPTION, same as -s.\n\
101 -a, --all print all information\n\
102 -m, --machine print the machine (hardware) type\n\
103 -n, --nodename print the machine's network node hostname\n\
104 -r, --release print the operating system release\n\
105 -s, --sysname print the operating system name\n\
106 -p, --processor print the host processor type\n\
107 -v print the operating system version\n\
108 --help display this help and exit\n\
109 --version output version information and exit\n"));
110 puts (_("\nReport bugs to <bug-sh-utils@gnu.org>."));
116 main (int argc
, char **argv
)
122 program_name
= argv
[0];
123 setlocale (LC_ALL
, "");
124 bindtextdomain (PACKAGE
, LOCALEDIR
);
125 textdomain (PACKAGE
);
129 while ((c
= getopt_long (argc
, argv
, "snrvpma", long_options
, NULL
)) != -1)
137 toprint
|= PRINT_SYSNAME
;
141 toprint
|= PRINT_NODENAME
;
145 toprint
|= PRINT_RELEASE
;
149 toprint
|= PRINT_VERSION
;
153 toprint
|= PRINT_MACHINE
;
157 toprint
|= PRINT_PROCESSOR
;
161 toprint
= (PRINT_SYSNAME
| PRINT_NODENAME
| PRINT_RELEASE
|
162 PRINT_PROCESSOR
| PRINT_VERSION
| PRINT_MACHINE
);
165 case_GETOPT_HELP_CHAR
;
167 case_GETOPT_VERSION_CHAR (PROGRAM_NAME
, AUTHORS
);
178 toprint
= PRINT_SYSNAME
;
180 if (uname (&name
) == -1)
181 error (1, errno
, _("cannot get system name"));
183 #if defined (HAVE_SYSINFO) && defined (SI_ARCHITECTURE)
184 if (sysinfo (SI_ARCHITECTURE
, processor
, sizeof (processor
)) == -1)
185 error (1, errno
, _("cannot get processor type"));
187 strcpy (processor
, "unknown");
190 print_element (PRINT_SYSNAME
, name
.sysname
);
191 print_element (PRINT_NODENAME
, name
.nodename
);
192 print_element (PRINT_RELEASE
, name
.release
);
193 print_element (PRINT_VERSION
, name
.version
);
194 print_element (PRINT_MACHINE
, name
.machine
);
195 print_element (PRINT_PROCESSOR
, processor
);
200 /* If the name element set in MASK is selected for printing in `toprint',
201 print ELEMENT; then print a space unless it is the last element to
202 be printed, in which case print a newline. */
205 print_element (unsigned int mask
, char *element
)
210 printf ("%s%c", element
, toprint
? ' ' : '\n');