diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-07-02 11:14:59 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-07-02 11:14:59 +0000 |
commit | e0a7fc54eb23f925d2ea885fb1b8699931f9001a (patch) | |
tree | 99cc437e3df9371efaa495c61cccabe2951c27ce /coreutils | |
parent | d4f72438e42f93117fb2633d5d435e475f7e69e2 (diff) | |
download | busybox-w32-e0a7fc54eb23f925d2ea885fb1b8699931f9001a.tar.gz busybox-w32-e0a7fc54eb23f925d2ea885fb1b8699931f9001a.tar.bz2 busybox-w32-e0a7fc54eb23f925d2ea885fb1b8699931f9001a.zip |
uname,individual: fix improper printf usage
uname,awk: small code shrink
function old new delta
uname_main 175 166 -9
nvalloc 167 157 -10
evaluate 6381 6370 -11
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-30) Total: -30 bytes
Diffstat (limited to 'coreutils')
-rw-r--r-- | coreutils/uname.c | 41 |
1 files changed, 19 insertions, 22 deletions
diff --git a/coreutils/uname.c b/coreutils/uname.c index 34600e7a9..76fd3ca8d 100644 --- a/coreutils/uname.c +++ b/coreutils/uname.c | |||
@@ -17,7 +17,7 @@ | |||
17 | -m, --machine sun | 17 | -m, --machine sun |
18 | -a, --all SunOS rocky8 4.0 sun | 18 | -a, --all SunOS rocky8 4.0 sun |
19 | 19 | ||
20 | The default behavior is equivalent to `-s'. | 20 | The default behavior is equivalent to '-s'. |
21 | 21 | ||
22 | David MacKenzie <djm@gnu.ai.mit.edu> */ | 22 | David MacKenzie <djm@gnu.ai.mit.edu> */ |
23 | 23 | ||
@@ -39,47 +39,43 @@ typedef struct { | |||
39 | } uname_info_t; | 39 | } uname_info_t; |
40 | 40 | ||
41 | static const char options[] ALIGN1 = "snrvmpa"; | 41 | static const char options[] ALIGN1 = "snrvmpa"; |
42 | static const unsigned short utsname_offset[] ALIGN2 = { | 42 | static const unsigned short utsname_offset[] = { |
43 | offsetof(uname_info_t,name.sysname), | 43 | offsetof(uname_info_t, name.sysname), |
44 | offsetof(uname_info_t,name.nodename), | 44 | offsetof(uname_info_t, name.nodename), |
45 | offsetof(uname_info_t,name.release), | 45 | offsetof(uname_info_t, name.release), |
46 | offsetof(uname_info_t,name.version), | 46 | offsetof(uname_info_t, name.version), |
47 | offsetof(uname_info_t,name.machine), | 47 | offsetof(uname_info_t, name.machine), |
48 | offsetof(uname_info_t,processor) | 48 | offsetof(uname_info_t, processor) |
49 | }; | 49 | }; |
50 | 50 | ||
51 | int uname_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 51 | int uname_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
52 | int uname_main(int argc, char **argv) | 52 | int uname_main(int argc ATTRIBUTE_UNUSED, char **argv) |
53 | { | 53 | { |
54 | uname_info_t uname_info; | 54 | uname_info_t uname_info; |
55 | #if defined(__sparc__) && defined(__linux__) | 55 | #if defined(__sparc__) && defined(__linux__) |
56 | char *fake_sparc = getenv("FAKE_SPARC"); | 56 | char *fake_sparc = getenv("FAKE_SPARC"); |
57 | #endif | 57 | #endif |
58 | const unsigned short int *delta; | 58 | const unsigned short *delta; |
59 | char toprint; | 59 | char toprint; |
60 | 60 | ||
61 | toprint = getopt32(argv, options); | 61 | toprint = getopt32(argv, options); |
62 | 62 | ||
63 | if (argc != optind) { | 63 | if (argv[optind]) { /* coreutils-6.9 compat */ |
64 | bb_show_usage(); | 64 | bb_show_usage(); |
65 | } | 65 | } |
66 | 66 | ||
67 | if (toprint & (1 << 6)) { | 67 | if (toprint & (1 << 6)) { /* -a => all opts on */ |
68 | toprint = 0x3f; | 68 | toprint = 0x3f; |
69 | } | 69 | } |
70 | 70 | ||
71 | if (toprint == 0) { | 71 | if (toprint == 0) { /* no opts => -s (sysname) */ |
72 | toprint = 1; /* sysname */ | 72 | toprint = 1; |
73 | } | 73 | } |
74 | 74 | ||
75 | if (uname(&uname_info.name) == -1) { | 75 | uname(&uname_info.name); /* never fails */ |
76 | bb_error_msg_and_die("cannot get system name"); | ||
77 | } | ||
78 | 76 | ||
79 | #if defined(__sparc__) && defined(__linux__) | 77 | #if defined(__sparc__) && defined(__linux__) |
80 | if ((fake_sparc != NULL) | 78 | if (fake_sparc && (fake_sparc[0] | 0x20) == 'y') { |
81 | && ((fake_sparc[0] == 'y') | ||
82 | || (fake_sparc[0] == 'Y'))) { | ||
83 | strcpy(uname_info.name.machine, "sparc"); | 79 | strcpy(uname_info.name.machine, "sparc"); |
84 | } | 80 | } |
85 | #endif | 81 | #endif |
@@ -89,7 +85,8 @@ int uname_main(int argc, char **argv) | |||
89 | delta = utsname_offset; | 85 | delta = utsname_offset; |
90 | do { | 86 | do { |
91 | if (toprint & 1) { | 87 | if (toprint & 1) { |
92 | printf("%s", ((char *)(&uname_info)) + *delta); | 88 | /* printf would not be safe here */ |
89 | fputs((char *)(&uname_info) + *delta, stdout); | ||
93 | if (toprint > 1) { | 90 | if (toprint > 1) { |
94 | bb_putchar(' '); | 91 | bb_putchar(' '); |
95 | } | 92 | } |
@@ -98,5 +95,5 @@ int uname_main(int argc, char **argv) | |||
98 | } while (toprint >>= 1); | 95 | } while (toprint >>= 1); |
99 | bb_putchar('\n'); | 96 | bb_putchar('\n'); |
100 | 97 | ||
101 | fflush_stdout_and_exit(EXIT_SUCCESS); | 98 | fflush_stdout_and_exit(EXIT_SUCCESS); /* coreutils-6.9 compat */ |
102 | } | 99 | } |