uname.c 1.5 KB

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