aboutsummaryrefslogtreecommitdiff
path: root/coreutils/uname.c
diff options
context:
space:
mode:
Diffstat (limited to 'coreutils/uname.c')
-rw-r--r--coreutils/uname.c38
1 files changed, 22 insertions, 16 deletions
diff --git a/coreutils/uname.c b/coreutils/uname.c
index df4f14ea0..a3e52e39f 100644
--- a/coreutils/uname.c
+++ b/coreutils/uname.c
@@ -16,6 +16,9 @@
16 along with this program; if not, write to the Free Software Foundation, 16 along with this program; if not, write to the Free Software Foundation,
17 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ 17 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
18 18
19/* BB_AUDIT SUSv3 compliant */
20/* http://www.opengroup.org/onlinepubs/007904975/utilities/uname.html */
21
19/* Option Example 22/* Option Example
20 23
21 -s, --sysname SunOS 24 -s, --sysname SunOS
@@ -33,13 +36,18 @@
33 36
34/* Further size reductions by Glenn McGrath and Manuel Novoa III. */ 37/* Further size reductions by Glenn McGrath and Manuel Novoa III. */
35 38
39/* Mar 16, 2003 Manuel Novoa III (mjn3@codepoet.org)
40 *
41 * Now does proper error checking on i/o. Plus some further space savings.
42 */
43
36#include <stdio.h> 44#include <stdio.h>
37#include <stdlib.h> 45#include <stdlib.h>
38#include <stddef.h> 46#include <stddef.h>
39#include <string.h> 47#include <string.h>
48#include <unistd.h>
40#include <sys/types.h> 49#include <sys/types.h>
41#include <sys/utsname.h> 50#include <sys/utsname.h>
42#include <getopt.h>
43#include "busybox.h" 51#include "busybox.h"
44 52
45typedef struct { 53typedef struct {
@@ -48,7 +56,6 @@ typedef struct {
48} uname_info_t; 56} uname_info_t;
49 57
50static const char options[] = "snrvmpa"; 58static const char options[] = "snrvmpa";
51static const char flags[] = "\x01\x02\x04\x08\x10\x20\x3f";
52static const unsigned short int utsname_offset[] = { 59static const unsigned short int utsname_offset[] = {
53 offsetof(uname_info_t,name.sysname), 60 offsetof(uname_info_t,name.sysname),
54 offsetof(uname_info_t,name.nodename), 61 offsetof(uname_info_t,name.nodename),
@@ -61,29 +68,28 @@ static const unsigned short int utsname_offset[] = {
61int uname_main(int argc, char **argv) 68int uname_main(int argc, char **argv)
62{ 69{
63 uname_info_t uname_info; 70 uname_info_t uname_info;
64
65#if defined(__sparc__) && defined(__linux__) 71#if defined(__sparc__) && defined(__linux__)
66 char *fake_sparc = getenv("FAKE_SPARC"); 72 char *fake_sparc = getenv("FAKE_SPARC");
67#endif 73#endif
68
69 const unsigned short int *delta; 74 const unsigned short int *delta;
70 int opt; 75 char toprint;
71 char toprint = 0;
72 76
73 while ((opt = getopt(argc, argv, options)) != -1) { 77 toprint = bb_getopt_ulflags(argc, argv, options);
74 const char *p = strchr(options,opt); 78
75 if (p == NULL) { 79 if (argc != optind) {
76 show_usage(); 80 bb_show_usage();
77 } 81 }
78 toprint |= flags[(int)(p-options)]; 82
83 if (toprint & (1 << 6)) {
84 toprint = 0x3f;
79 } 85 }
80 86
81 if (toprint == 0) { 87 if (toprint == 0) {
82 toprint = flags[0]; /* sysname */ 88 toprint = 1; /* sysname */
83 } 89 }
84 90
85 if (uname(&uname_info.name) == -1) { 91 if (uname(&uname_info.name) == -1) {
86 error_msg_and_die("cannot get system name"); 92 bb_error_msg_and_die("cannot get system name");
87 } 93 }
88 94
89#if defined(__sparc__) && defined(__linux__) 95#if defined(__sparc__) && defined(__linux__)
@@ -99,7 +105,7 @@ int uname_main(int argc, char **argv)
99 delta=utsname_offset; 105 delta=utsname_offset;
100 do { 106 do {
101 if (toprint & 1) { 107 if (toprint & 1) {
102 printf(((char *)(&uname_info)) + *delta); 108 bb_printf(((char *)(&uname_info)) + *delta);
103 if (toprint > 1) { 109 if (toprint > 1) {
104 putchar(' '); 110 putchar(' ');
105 } 111 }
@@ -108,5 +114,5 @@ int uname_main(int argc, char **argv)
108 } while (toprint >>= 1); 114 } while (toprint >>= 1);
109 putchar('\n'); 115 putchar('\n');
110 116
111 return EXIT_SUCCESS; 117 bb_fflush_stdout_and_exit(EXIT_SUCCESS);
112} 118}