sbase

suckless unix tools
git clone git://git.suckless.org/sbase
Log | Files | Refs | README | LICENSE

uname.c (952B)


      1 /* See LICENSE file for copyright and license details. */
      2 #include <sys/utsname.h>
      3 
      4 #include <stdio.h>
      5 
      6 #include "util.h"
      7 
      8 static void
      9 usage(void)
     10 {
     11 	eprintf("usage: %s [-amnrsv]\n", argv0);
     12 }
     13 
     14 int
     15 main(int argc, char *argv[])
     16 {
     17 	struct utsname u;
     18 	int mflag = 0, nflag = 0, rflag = 0, sflag = 0, vflag = 0;
     19 
     20 	ARGBEGIN {
     21 	case 'a':
     22 		mflag = nflag = rflag = sflag = vflag = 1;
     23 		break;
     24 	case 'm':
     25 		mflag = 1;
     26 		break;
     27 	case 'n':
     28 		nflag = 1;
     29 		break;
     30 	case 'r':
     31 		rflag = 1;
     32 		break;
     33 	case 's':
     34 		sflag = 1;
     35 		break;
     36 	case 'v':
     37 		vflag = 1;
     38 		break;
     39 	default:
     40 		usage();
     41 	} ARGEND
     42 
     43 	if (argc)
     44 		usage();
     45 
     46 	if (uname(&u) < 0)
     47 		eprintf("uname:");
     48 
     49 	if (sflag || !(nflag || rflag || vflag || mflag))
     50 		putword(stdout, u.sysname);
     51 	if (nflag)
     52 		putword(stdout, u.nodename);
     53 	if (rflag)
     54 		putword(stdout, u.release);
     55 	if (vflag)
     56 		putword(stdout, u.version);
     57 	if (mflag)
     58 		putword(stdout, u.machine);
     59 	putchar('\n');
     60 
     61 	return fshut(stdout, "<stdout>");
     62 }