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