Annotation of /trunk/mkinitrd-magellan/busybox/coreutils/uname.c
Parent Directory | Revision Log
Revision 816 -
(hide annotations)
(download)
Fri Apr 24 18:33:46 2009 UTC (15 years, 1 month ago) by niro
File MIME type: text/plain
File size: 2383 byte(s)
Fri Apr 24 18:33:46 2009 UTC (15 years, 1 month ago) by niro
File MIME type: text/plain
File size: 2383 byte(s)
-updated to busybox-1.13.4
1 | niro | 532 | /* vi: set sw=4 ts=4: */ |
2 | /* uname -- print system information | ||
3 | * Copyright (C) 1989-1999 Free Software Foundation, Inc. | ||
4 | * | ||
5 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. | ||
6 | */ | ||
7 | |||
8 | /* BB_AUDIT SUSv3 compliant */ | ||
9 | /* http://www.opengroup.org/onlinepubs/007904975/utilities/uname.html */ | ||
10 | |||
11 | /* Option Example | ||
12 | |||
13 | -s, --sysname SunOS | ||
14 | -n, --nodename rocky8 | ||
15 | -r, --release 4.0 | ||
16 | -v, --version | ||
17 | -m, --machine sun | ||
18 | -a, --all SunOS rocky8 4.0 sun | ||
19 | |||
20 | niro | 816 | The default behavior is equivalent to '-s'. |
21 | niro | 532 | |
22 | David MacKenzie <djm@gnu.ai.mit.edu> */ | ||
23 | |||
24 | /* Busyboxed by Erik Andersen */ | ||
25 | |||
26 | /* Further size reductions by Glenn McGrath and Manuel Novoa III. */ | ||
27 | |||
28 | /* Mar 16, 2003 Manuel Novoa III (mjn3@codepoet.org) | ||
29 | * | ||
30 | * Now does proper error checking on i/o. Plus some further space savings. | ||
31 | */ | ||
32 | |||
33 | #include <sys/utsname.h> | ||
34 | niro | 816 | #include "libbb.h" |
35 | niro | 532 | |
36 | typedef struct { | ||
37 | struct utsname name; | ||
38 | char processor[8]; /* for "unknown" */ | ||
39 | } uname_info_t; | ||
40 | |||
41 | niro | 816 | static const char options[] ALIGN1 = "snrvmpa"; |
42 | static const unsigned short utsname_offset[] = { | ||
43 | offsetof(uname_info_t, name.sysname), | ||
44 | offsetof(uname_info_t, name.nodename), | ||
45 | offsetof(uname_info_t, name.release), | ||
46 | offsetof(uname_info_t, name.version), | ||
47 | offsetof(uname_info_t, name.machine), | ||
48 | offsetof(uname_info_t, processor) | ||
49 | niro | 532 | }; |
50 | |||
51 | niro | 816 | int uname_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
52 | int uname_main(int argc UNUSED_PARAM, char **argv) | ||
53 | niro | 532 | { |
54 | uname_info_t uname_info; | ||
55 | #if defined(__sparc__) && defined(__linux__) | ||
56 | char *fake_sparc = getenv("FAKE_SPARC"); | ||
57 | #endif | ||
58 | niro | 816 | const unsigned short *delta; |
59 | niro | 532 | char toprint; |
60 | |||
61 | niro | 816 | toprint = getopt32(argv, options); |
62 | niro | 532 | |
63 | niro | 816 | if (argv[optind]) { /* coreutils-6.9 compat */ |
64 | niro | 532 | bb_show_usage(); |
65 | } | ||
66 | |||
67 | niro | 816 | if (toprint & (1 << 6)) { /* -a => all opts on */ |
68 | niro | 532 | toprint = 0x3f; |
69 | } | ||
70 | |||
71 | niro | 816 | if (toprint == 0) { /* no opts => -s (sysname) */ |
72 | toprint = 1; | ||
73 | niro | 532 | } |
74 | |||
75 | niro | 816 | uname(&uname_info.name); /* never fails */ |
76 | niro | 532 | |
77 | #if defined(__sparc__) && defined(__linux__) | ||
78 | niro | 816 | if (fake_sparc && (fake_sparc[0] | 0x20) == 'y') { |
79 | niro | 532 | strcpy(uname_info.name.machine, "sparc"); |
80 | } | ||
81 | #endif | ||
82 | |||
83 | strcpy(uname_info.processor, "unknown"); | ||
84 | |||
85 | delta = utsname_offset; | ||
86 | do { | ||
87 | if (toprint & 1) { | ||
88 | niro | 816 | /* printf would not be safe here */ |
89 | fputs((char *)(&uname_info) + *delta, stdout); | ||
90 | niro | 532 | if (toprint > 1) { |
91 | niro | 816 | bb_putchar(' '); |
92 | niro | 532 | } |
93 | } | ||
94 | ++delta; | ||
95 | } while (toprint >>= 1); | ||
96 | niro | 816 | bb_putchar('\n'); |
97 | niro | 532 | |
98 | niro | 816 | fflush_stdout_and_exit(EXIT_SUCCESS); /* coreutils-6.9 compat */ |
99 | niro | 532 | } |