toybox/toys/posix/uname.c
<<
>>
Prefs
   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
   6
   7USE_UNAME(NEWTOY(uname, "aomvrns", TOYFLAG_BIN))
   8USE_ARCH(NEWTOY(arch, 0, TOYFLAG_USR|TOYFLAG_BIN))
   9USE_LINUX32(NEWTOY(linux32, 0, TOYFLAG_USR|TOYFLAG_BIN))
  10
  11config ARCH 
  12  bool "arch"
  13  default y
  14  help
  15    usage: arch
  16
  17    Print machine (hardware) name, same as uname -m.
  18
  19config LINUX32
  20  bool "linux32"
  21  default y
  22  help
  23    usage: linux32 [COMMAND...]
  24
  25    Tell uname -m to line to autoconf (to build 32 bit binaries on 64 bit kernel).
  26
  27config UNAME
  28  bool "uname"
  29  default y
  30  help
  31    usage: uname [-asnrvm]
  32
  33    Print system information.
  34
  35    -s  System name
  36    -n  Network (domain) name
  37    -r  Kernel Release number
  38    -v  Kernel Version 
  39    -m  Machine (hardware) name
  40    -o  Userspace type
  41    -a  All of the above (in order)
  42*/
  43
  44#define FOR_uname
  45#define FORCE_FLAGS
  46#include "toys.h"
  47
  48void uname_main(void)
  49{
  50  int i, needspace = 0;
  51  char *c;
  52
  53  uname((void *)toybuf);
  54  if (!toys.optflags) toys.optflags = FLAG_s;
  55  for (i=0; i<6; i++) if (toys.optflags & ((1<<i)|FLAG_a)) {
  56    if (i==5) c = " Toybox"+!needspace;
  57    else {
  58      c = toybuf+sizeof(((struct utsname *)0)->sysname)*i;
  59      if (needspace++) *(--c)=' '; // Can't decrement first entry
  60    }
  61    xputsn(c);
  62  }
  63  xputc('\n');
  64}
  65
  66void arch_main(void)
  67{
  68  toys.optflags = FLAG_m;
  69  uname_main();
  70}
  71
  72void linux32_main(void)
  73{
  74  personality(PER_LINUX32);
  75  xexec(toys.optc ? toys.optargs : (char *[]){"/bin/sh", 0});
  76}
  77