aboutsummaryrefslogtreecommitdiff
path: root/toys/posix/uname.c
blob: dfa5762ffb09b77166dc8d83c813198369980456 (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
/* 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, "paomvrns", TOYFLAG_BIN))
USE_ARCH(NEWTOY(arch, 0, TOYFLAG_USR|TOYFLAG_BIN))

config ARCH
  bool "arch"
  default y
  help
    usage: arch

    Print machine (hardware) name, same as uname -m.

config UNAME
  bool "uname"
  default y
  help
    usage: uname [-asnrvmo]

    Print system information.

    -s	System name
    -n	Network (domain) name
    -r	Kernel Release number
    -v	Kernel Version
    -m	Machine (hardware) name
    -a	All of the above (in order)

    -o	Userspace type
*/

#define FOR_uname
#define FORCE_FLAGS
#include "toys.h"

void uname_main(void)
{
  int i, needspace = 0;
  char *c;

  uname((void *)toybuf);
  if (!toys.optflags) toys.optflags = FLAG_s;
  for (i=0; i<6; i++) if (toys.optflags & ((1<<i)|FLAG_a)) {
    if (i==5) c = " Toybox"+!needspace;
    else {
      c = toybuf+sizeof(((struct utsname *)0)->sysname)*i;
      if (needspace++) *(--c)=' '; // Can't decrement first entry
    }
    xputsn(c);
  }
  if (FLAG(p)) xputsn(" unknown"+!needspace);
  xputc('\n');
}

void arch_main(void)
{
  toys.optflags = FLAG_m;
  uname_main();
}