10f66f451Sopenharmony_ci/* uname.c - return system name 20f66f451Sopenharmony_ci * 30f66f451Sopenharmony_ci * Copyright 2008 Rob Landley <rob@landley.net> 40f66f451Sopenharmony_ci * 50f66f451Sopenharmony_ci * See http://opengroup.org/onlinepubs/9699919799/utilities/uname.html 60f66f451Sopenharmony_ci 70f66f451Sopenharmony_ciUSE_UNAME(NEWTOY(uname, "oamvrns[+os]", TOYFLAG_BIN)) 80f66f451Sopenharmony_ciUSE_ARCH(NEWTOY(arch, 0, TOYFLAG_USR|TOYFLAG_BIN)) 90f66f451Sopenharmony_ci 100f66f451Sopenharmony_ciconfig ARCH 110f66f451Sopenharmony_ci bool "arch" 120f66f451Sopenharmony_ci default y 130f66f451Sopenharmony_ci help 140f66f451Sopenharmony_ci usage: arch 150f66f451Sopenharmony_ci 160f66f451Sopenharmony_ci Print machine (hardware) name, same as uname -m. 170f66f451Sopenharmony_ci 180f66f451Sopenharmony_ciconfig UNAME 190f66f451Sopenharmony_ci bool "uname" 200f66f451Sopenharmony_ci default y 210f66f451Sopenharmony_ci help 220f66f451Sopenharmony_ci usage: uname [-asnrvm] 230f66f451Sopenharmony_ci 240f66f451Sopenharmony_ci Print system information. 250f66f451Sopenharmony_ci 260f66f451Sopenharmony_ci -s System name 270f66f451Sopenharmony_ci -n Network (domain) name 280f66f451Sopenharmony_ci -r Kernel Release number 290f66f451Sopenharmony_ci -v Kernel Version 300f66f451Sopenharmony_ci -m Machine (hardware) name 310f66f451Sopenharmony_ci -a All of the above 320f66f451Sopenharmony_ci*/ 330f66f451Sopenharmony_ci 340f66f451Sopenharmony_ci#define FOR_uname 350f66f451Sopenharmony_ci#define FORCE_FLAGS 360f66f451Sopenharmony_ci#include "toys.h" 370f66f451Sopenharmony_ci 380f66f451Sopenharmony_ci// If a 32 bit x86 build environment working in a chroot under an x86-64 390f66f451Sopenharmony_ci// kernel returns x86_64 for -m it confuses ./configure. Special case it. 400f66f451Sopenharmony_ci 410f66f451Sopenharmony_ci#if defined(__i686__) 420f66f451Sopenharmony_ci#define GROSS "i686" 430f66f451Sopenharmony_ci#elif defined(__i586__) 440f66f451Sopenharmony_ci#define GROSS "i586" 450f66f451Sopenharmony_ci#elif defined(__i486__) 460f66f451Sopenharmony_ci#define GROSS "i486" 470f66f451Sopenharmony_ci#elif defined(__i386__) 480f66f451Sopenharmony_ci#define GROSS "i386" 490f66f451Sopenharmony_ci#endif 500f66f451Sopenharmony_ci 510f66f451Sopenharmony_civoid uname_main(void) 520f66f451Sopenharmony_ci{ 530f66f451Sopenharmony_ci int i, flags = toys.optflags, needspace=0; 540f66f451Sopenharmony_ci struct utsname u; 550f66f451Sopenharmony_ci 560f66f451Sopenharmony_ci uname(&u); 570f66f451Sopenharmony_ci 580f66f451Sopenharmony_ci if (!flags) flags = FLAG_s; 590f66f451Sopenharmony_ci for (i=0; i<5; i++) { 600f66f451Sopenharmony_ci char *c = ((char *) &u)+(sizeof(u.sysname)*i); 610f66f451Sopenharmony_ci 620f66f451Sopenharmony_ci if (flags & ((1<<i)|FLAG_a)) { 630f66f451Sopenharmony_ci int len = strlen(c); 640f66f451Sopenharmony_ci 650f66f451Sopenharmony_ci // This problem originates in autoconf, so of course the solution 660f66f451Sopenharmony_ci // is horribly ugly. 670f66f451Sopenharmony_ci#ifdef GROSS 680f66f451Sopenharmony_ci if (i==4 && !strcmp(c,"x86_64")) { 690f66f451Sopenharmony_ci printf(GROSS); 700f66f451Sopenharmony_ci continue; 710f66f451Sopenharmony_ci } 720f66f451Sopenharmony_ci#endif 730f66f451Sopenharmony_ci 740f66f451Sopenharmony_ci if (needspace++) { 750f66f451Sopenharmony_ci // We can't decrement on the first entry, because 760f66f451Sopenharmony_ci // needspace would be 0 770f66f451Sopenharmony_ci *(--c)=' '; 780f66f451Sopenharmony_ci len++; 790f66f451Sopenharmony_ci } 800f66f451Sopenharmony_ci xwrite(1, c, len); 810f66f451Sopenharmony_ci } 820f66f451Sopenharmony_ci } 830f66f451Sopenharmony_ci putchar('\n'); 840f66f451Sopenharmony_ci} 850f66f451Sopenharmony_ci 860f66f451Sopenharmony_civoid arch_main(void) 870f66f451Sopenharmony_ci{ 880f66f451Sopenharmony_ci toys.optflags = FLAG_m; 890f66f451Sopenharmony_ci uname_main(); 900f66f451Sopenharmony_ci} 91