aboutsummaryrefslogtreecommitdiff
path: root/toys/posix/uname.c
blob: 3c774b3c11cac76fbc43f8558b0e3b641033b722 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/* vi: set sw=4 ts=4:
 *
 * uname.c - return system name
 *
 * Copyright 2008 Rob Landley <rob@landley.net>
 *
 * See http://opengroup.org/onlinepubs/9699919799/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
*/

#define FOR_uname
#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

void uname_main(void)
{
	int i, flags = toys.optflags, needspace=0;

	uname((void *)toybuf);

	if (!flags) flags = FLAG_s;
	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');
}