Home | History | Annotate | Download | only in posix
      1 /* uname.c - return system name
      2  *
      3  * Copyright 2008 Rob Landley <rob (at) landley.net>
      4  *
      5  * See http://opengroup.org/onlinepubs/9699919799/utilities/uname.html
      6 
      7 USE_UNAME(NEWTOY(uname, "oamvrns[+os]", TOYFLAG_BIN))
      8 
      9 config UNAME
     10   bool "uname"
     11   default y
     12   help
     13     usage: uname [-asnrvm]
     14 
     15     Print system information.
     16 
     17     -s	System name
     18     -n	Network (domain) name
     19     -r	Kernel Release number
     20     -v	Kernel Version
     21     -m	Machine (hardware) name
     22     -a	All of the above
     23 */
     24 
     25 #define FOR_uname
     26 #include "toys.h"
     27 
     28 // If a 32 bit x86 build environment working in a chroot under an x86-64
     29 // kernel returns x86_64 for -m it confuses ./configure.  Special case it.
     30 
     31 #if defined(__i686__)
     32 #define GROSS "i686"
     33 #elif defined(__i586__)
     34 #define GROSS "i586"
     35 #elif defined(__i486__)
     36 #define GROSS "i486"
     37 #elif defined(__i386__)
     38 #define GROSS "i386"
     39 #endif
     40 
     41 void uname_main(void)
     42 {
     43   int i, flags = toys.optflags, needspace=0;
     44   struct utsname u;
     45 
     46   uname(&u);
     47 
     48   if (!flags) flags = FLAG_s;
     49   for (i=0; i<5; i++) {
     50     char *c = ((char *) &u)+(sizeof(u.sysname)*i);
     51 
     52     if (flags & ((1<<i)|FLAG_a)) {
     53       int len = strlen(c);
     54 
     55       // This problem originates in autoconf, so of course the solution
     56       // is horribly ugly.
     57 #ifdef GROSS
     58       if (i==4 && !strcmp(c,"x86_64")) {
     59         printf(GROSS);
     60         continue;
     61       }
     62 #endif
     63 
     64       if (needspace++) {
     65         // We can't decrement on the first entry, because
     66         // needspace would be 0
     67         *(--c)=' ';
     68         len++;
     69       }
     70       xwrite(1, c, len);
     71     }
     72   }
     73   putchar('\n');
     74 }
     75