Mercurial > hg > toybox
annotate toys/posix/uname.c @ 656:6df4ccc0acbe
Regularize command headers, update links to standards documents.
author | Rob Landley <rob@landley.net> |
---|---|
date | Sat, 25 Aug 2012 18:08:51 -0500 |
parents | 2986aa63a021 |
children | 7e846e281e38 |
rev | line source |
---|---|
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 * | |
656
6df4ccc0acbe
Regularize command headers, update links to standards documents.
Rob Landley <rob@landley.net>
parents:
653
diff
changeset
|
7 * See http://opengroup.org/onlinepubs/9699919799/utilities/uname.html |
326 | 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 | |
29 // If a 32 bit x86 build environment working in a chroot under an x86-64 | |
30 // kernel returns x86_64 for -m it confuses ./configure. Special case it. | |
31 | |
32 #if defined(__i686__) | |
33 #define GROSS "i686" | |
34 #elif defined(__i586__) | |
35 #define GROSS "i586" | |
36 #elif defined(__i486__) | |
37 #define GROSS "i486" | |
38 #elif defined(__i386__) | |
39 #define GROSS "i386" | |
40 #endif | |
41 | |
42 #define FLAG_a (1<<5) | |
43 | |
44 void uname_main(void) | |
45 { | |
46 int i, flags = toys.optflags, needspace=0; | |
47 | |
48 uname((void *)toybuf); | |
49 | |
50 if (!flags) flags=1; | |
51 for (i=0; i<5; i++) { | |
52 char *c = toybuf+(65*i); | |
53 | |
54 if (flags & ((1<<i)|FLAG_a)) { | |
55 int len = strlen(c); | |
56 | |
57 // This problem originates in autoconf, so of course the solution | |
58 // is horribly ugly. | |
59 #ifdef GROSS | |
327 | 60 if (i==4 && !strcmp(c,"x86_64")) printf(GROSS); |
326 | 61 else |
62 #endif | |
63 | |
64 if (needspace++) { | |
65 // We can't decrement on the first entry, because | |
66 // needspace would be 0 | |
67 *(--c)=' '; | |
68 len++; | |
69 } | |
70 xwrite(1, c, len); | |
71 } | |
72 } | |
73 putchar('\n'); | |
74 } |