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