326
|
1 /* vi: set sw=4 ts=4:
|
|
2 *
|
|
3 * uname.c - return system name
|
|
4 *
|
|
5 * Copyright 2008 Rob Landley <rob@landley.net>
|
|
6 *
|
|
7 * See http://www.opengroup.org/onlinepubs/009695399/utilities/uname.html
|
|
8
|
|
9 USE_UNAME(NEWTOY(uname, "amvrns", TOYFLAG_BIN))
|
|
10
|
|
11 config UNAME
|
|
12 bool "uname"
|
|
13 default y
|
|
14 help
|
|
15 usage: uname [-asnrvmpio]
|
|
16
|
|
17 Print system information.
|
|
18
|
|
19 -s System name
|
|
20 -n Network (domain) name
|
|
21 -r Release number
|
|
22 -v Version (build date)
|
|
23 -m Machine (hardware) name
|
|
24 -a All of the above
|
|
25 */
|
|
26
|
|
27 #include "toys.h"
|
|
28 #include <sys/utsname.h>
|
|
29
|
|
30 // If a 32 bit x86 build environment working in a chroot under an x86-64
|
|
31 // kernel returns x86_64 for -m it confuses ./configure. Special case it.
|
|
32
|
|
33 #if defined(__i686__)
|
|
34 #define GROSS "i686"
|
|
35 #elif defined(__i586__)
|
|
36 #define GROSS "i586"
|
|
37 #elif defined(__i486__)
|
|
38 #define GROSS "i486"
|
|
39 #elif defined(__i386__)
|
|
40 #define GROSS "i386"
|
|
41 #endif
|
|
42
|
|
43 #define FLAG_a (1<<5)
|
|
44
|
|
45 void uname_main(void)
|
|
46 {
|
|
47 int i, flags = toys.optflags, needspace=0;
|
|
48
|
|
49 uname((void *)toybuf);
|
|
50
|
|
51 if (!flags) flags=1;
|
|
52 for (i=0; i<5; i++) {
|
|
53 char *c = toybuf+(65*i);
|
|
54
|
|
55 if (flags & ((1<<i)|FLAG_a)) {
|
|
56 int len = strlen(c);
|
|
57
|
|
58 // This problem originates in autoconf, so of course the solution
|
|
59 // is horribly ugly.
|
|
60 #ifdef GROSS
|
327
|
61 if (i==4 && !strcmp(c,"x86_64")) printf(GROSS);
|
326
|
62 else
|
|
63 #endif
|
|
64
|
|
65 if (needspace++) {
|
|
66 // We can't decrement on the first entry, because
|
|
67 // needspace would be 0
|
|
68 *(--c)=' ';
|
|
69 len++;
|
|
70 }
|
|
71 xwrite(1, c, len);
|
|
72 }
|
|
73 }
|
|
74 putchar('\n');
|
|
75 }
|