toybox

view toys/posix/uname.c @ 1531:3ff823086c99

Teach ln -f to leave original target alone if link creation fails. Suggested by Ashwini Sharma, I wound up implementing it by creating the new link at a temporary name and renaming it over the old one instead of renaming the old file out of the way and putting it back if it failed. (Because "mkdir -p one/one/blah && ln -sf /bin/one one" would otherwise rename one/one out of the way and only notice it can't delete it way at the end when recovery's darn awkward, vs create new thing and if rename fails (including EISDIR) that's the main error path. And yes the temporary name is in the same directory as the destination so we never rename between mounts.) link over the old one instead of renaming the old file and renaming it back.
author Rob Landley <rob@landley.net>
date Wed, 22 Oct 2014 17:11:06 -0500
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 }