aboutsummaryrefslogtreecommitdiff
path: root/toys/posix/uname.c
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2012-08-25 14:25:22 -0500
committerRob Landley <rob@landley.net>2012-08-25 14:25:22 -0500
commit3a9241add947cb6d24b5de7a8927517426a78795 (patch)
treed122ab6570439cd6b17c7d73ed8d4e085e0b8a95 /toys/posix/uname.c
parent689f095bc976417bf50810fe59a3b3ac32b21105 (diff)
downloadtoybox-3a9241add947cb6d24b5de7a8927517426a78795.tar.gz
Move commands into "posix", "lsb", and "other" menus/directories.
Diffstat (limited to 'toys/posix/uname.c')
-rw-r--r--toys/posix/uname.c74
1 files changed, 74 insertions, 0 deletions
diff --git a/toys/posix/uname.c b/toys/posix/uname.c
new file mode 100644
index 00000000..185d633e
--- /dev/null
+++ b/toys/posix/uname.c
@@ -0,0 +1,74 @@
+/* vi: set sw=4 ts=4:
+ *
+ * uname.c - return system name
+ *
+ * Copyright 2008 Rob Landley <rob@landley.net>
+ *
+ * See http://www.opengroup.org/onlinepubs/009695399/utilities/uname.html
+
+USE_UNAME(NEWTOY(uname, "amvrns", TOYFLAG_BIN))
+
+config UNAME
+ bool "uname"
+ default y
+ help
+ usage: uname [-asnrvmpio]
+
+ Print system information.
+
+ -s System name
+ -n Network (domain) name
+ -r Release number
+ -v Version (build date)
+ -m Machine (hardware) name
+ -a All of the above
+*/
+
+#include "toys.h"
+
+// If a 32 bit x86 build environment working in a chroot under an x86-64
+// kernel returns x86_64 for -m it confuses ./configure. Special case it.
+
+#if defined(__i686__)
+#define GROSS "i686"
+#elif defined(__i586__)
+#define GROSS "i586"
+#elif defined(__i486__)
+#define GROSS "i486"
+#elif defined(__i386__)
+#define GROSS "i386"
+#endif
+
+#define FLAG_a (1<<5)
+
+void uname_main(void)
+{
+ int i, flags = toys.optflags, needspace=0;
+
+ uname((void *)toybuf);
+
+ if (!flags) flags=1;
+ for (i=0; i<5; i++) {
+ char *c = toybuf+(65*i);
+
+ if (flags & ((1<<i)|FLAG_a)) {
+ int len = strlen(c);
+
+ // This problem originates in autoconf, so of course the solution
+ // is horribly ugly.
+#ifdef GROSS
+ if (i==4 && !strcmp(c,"x86_64")) printf(GROSS);
+ else
+#endif
+
+ if (needspace++) {
+ // We can't decrement on the first entry, because
+ // needspace would be 0
+ *(--c)=' ';
+ len++;
+ }
+ xwrite(1, c, len);
+ }
+ }
+ putchar('\n');
+}