2 * uname - print system information
4 * usage: uname [-amnrsv]
9 Copyright (C) 1999-2009 Free Software Foundation, Inc.
11 This file is part of GNU Bush.
12 Bush is free software: you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation, either version 3 of the License, or
15 (at your option) any later version.
17 Bush is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with Bush. If not, see <http://www.gnu.org/licenses/>.
29 #include "bushtypes.h"
31 #if defined (HAVE_UNAME)
32 # include <sys/utsname.h>
47 #include "bushgetopt.h"
50 #define FLAG_SYSNAME 0x01 /* -s */
51 #define FLAG_NODENAME 0x02 /* -n */
52 #define FLAG_RELEASE 0x04 /* -r */
53 #define FLAG_VERSION 0x08 /* -v */
54 #define FLAG_MACHINE 0x10 /* -m, -p */
64 static int uname_flags
;
71 struct utsname uninfo
;
74 reset_internal_getopt ();
75 while ((opt
= internal_getopt (list
, "amnprsv")) != -1)
80 uname_flags
|= FLAG_ALL
;
84 uname_flags
|= FLAG_MACHINE
;
87 uname_flags
|= FLAG_NODENAME
;
90 uname_flags
|= FLAG_RELEASE
;
93 uname_flags
|= FLAG_SYSNAME
;
96 uname_flags
|= FLAG_VERSION
;
112 if (uname_flags
== 0)
113 uname_flags
= FLAG_SYSNAME
;
115 /* Only ancient systems will not have uname(2). */
117 if (uname (&uninfo
) < 0)
119 builtin_error ("cannot get system name: %s", strerror (errno
));
120 return (EXECUTION_FAILURE
);
123 builtin_error ("cannot get system information: uname(2) not available");
124 return (EXECUTION_FAILURE
);
127 uprint (FLAG_SYSNAME
, uninfo
.sysname
);
128 uprint (FLAG_NODENAME
, uninfo
.nodename
);
129 uprint (FLAG_RELEASE
, uninfo
.release
);
130 uprint (FLAG_VERSION
, uninfo
.version
);
131 uprint (FLAG_MACHINE
, uninfo
.machine
);
133 return (EXECUTION_SUCCESS
);
141 if (uname_flags
& flag
)
143 uname_flags
&= ~flag
;
144 printf ("%s%c", info
, uname_flags
? ' ' : '\n');
148 char *uname_doc
[] = {
149 "Display system information.",
151 "Display information about the system hardware and OS.",
155 struct builtin uname_struct
= {