Magellan Linux

Annotation of /trunk/mkinitrd-magellan/busybox/coreutils/uname.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 532 - (hide annotations) (download)
Sat Sep 1 22:45:15 2007 UTC (16 years, 8 months ago) by niro
File MIME type: text/plain
File size: 2375 byte(s)
-import if magellan mkinitrd; it is a fork of redhats mkinitrd-5.0.8 with all magellan patches and features; deprecates magellan-src/mkinitrd

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     The default behavior is equivalent to `-s'.
21    
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 <stdio.h>
34     #include <stdlib.h>
35     #include <stddef.h>
36     #include <string.h>
37     #include <unistd.h>
38     #include <sys/types.h>
39     #include <sys/utsname.h>
40     #include "busybox.h"
41    
42     typedef struct {
43     struct utsname name;
44     char processor[8]; /* for "unknown" */
45     } uname_info_t;
46    
47     static const char options[] = "snrvmpa";
48     static const unsigned short int utsname_offset[] = {
49     offsetof(uname_info_t,name.sysname),
50     offsetof(uname_info_t,name.nodename),
51     offsetof(uname_info_t,name.release),
52     offsetof(uname_info_t,name.version),
53     offsetof(uname_info_t,name.machine),
54     offsetof(uname_info_t,processor)
55     };
56    
57     int uname_main(int argc, char **argv)
58     {
59     uname_info_t uname_info;
60     #if defined(__sparc__) && defined(__linux__)
61     char *fake_sparc = getenv("FAKE_SPARC");
62     #endif
63     const unsigned short int *delta;
64     char toprint;
65    
66     toprint = getopt32(argc, argv, options);
67    
68     if (argc != optind) {
69     bb_show_usage();
70     }
71    
72     if (toprint & (1 << 6)) {
73     toprint = 0x3f;
74     }
75    
76     if (toprint == 0) {
77     toprint = 1; /* sysname */
78     }
79    
80     if (uname(&uname_info.name) == -1) {
81     bb_error_msg_and_die("cannot get system name");
82     }
83    
84     #if defined(__sparc__) && defined(__linux__)
85     if ((fake_sparc != NULL)
86     && ((fake_sparc[0] == 'y')
87     || (fake_sparc[0] == 'Y'))) {
88     strcpy(uname_info.name.machine, "sparc");
89     }
90     #endif
91    
92     strcpy(uname_info.processor, "unknown");
93    
94     delta = utsname_offset;
95     do {
96     if (toprint & 1) {
97     printf(((char *)(&uname_info)) + *delta);
98     if (toprint > 1) {
99     putchar(' ');
100     }
101     }
102     ++delta;
103     } while (toprint >>= 1);
104     putchar('\n');
105    
106     fflush_stdout_and_exit(EXIT_SUCCESS);
107     }