toybox

view toys/posix/uname.c @ 1571:e85e5f3b87c2

As long as Android's going to require fortify, fixup the warnings it generates.
author Rob Landley <rob@landley.net>
date Sat, 22 Nov 2014 00:36:45 -0600
parents b89ab13436fa
children
line source
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
7 USE_UNAME(NEWTOY(uname, "oamvrns[+os]", TOYFLAG_BIN))
9 config UNAME
10 bool "uname"
11 default y
12 help
13 usage: uname [-asnrvm]
15 Print system information.
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 */
25 #define FOR_uname
26 #include "toys.h"
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.
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
41 void uname_main(void)
42 {
43 int i, flags = toys.optflags, needspace=0;
45 uname((void *)toybuf);
47 if (!flags) flags = FLAG_s;
48 for (i=0; i<5; i++) {
49 char *c = toybuf+(65*i);
51 if (flags & ((1<<i)|FLAG_a)) {
52 int len = strlen(c);
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
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 }