annotate toys/uname.c @ 562:4d802d438983

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