1 /* $NetBSD: uname.c,v 1.9 1997/10/20 02:16:39 lukem Exp $ */ 2 3 /* 4 * Copyright (c) 1994 Winning Strategies, Inc. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. All advertising materials mentioning features or use of this software 16 * must display the following acknowledgement: 17 * This product includes software developed by Winning Strategies, Inc. 18 * 4. The name of Winning Strategies, Inc. may not be used to endorse or 19 * promote products derived from this software without specific prior 20 * written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 */ 33 34 #include <sys/cdefs.h> 35 #ifndef lint 36 __RCSID("$NetBSD: uname.c,v 1.9 1997/10/20 02:16:39 lukem Exp $"); 37 #endif /* not lint */ 38 39 #include <stdio.h> 40 #include <locale.h> 41 #include <unistd.h> 42 #include <sys/utsname.h> 43 #include <err.h> 44 45 int main __P((int, char **)); 46 static void usage __P((void)); 47 48 #define PRINT_SYSNAME 0x01 49 #define PRINT_NODENAME 0x02 50 #define PRINT_RELEASE 0x04 51 #define PRINT_VERSION 0x08 52 #define PRINT_MACHINE 0x10 53 #define PRINT_ALL 0x1f 54 55 int 56 main(argc, argv) 57 int argc; 58 char **argv; 59 { 60 struct utsname u; 61 int c; 62 int space = 0; 63 int print_mask = 0; 64 65 setlocale(LC_ALL, ""); 66 67 while ((c = getopt(argc,argv,"amnrsv")) != -1 ) { 68 switch ( c ) { 69 case 'a': 70 print_mask |= PRINT_ALL; 71 break; 72 case 'm': 73 print_mask |= PRINT_MACHINE; 74 break; 75 case 'n': 76 print_mask |= PRINT_NODENAME; 77 break; 78 case 'r': 79 print_mask |= PRINT_RELEASE; 80 break; 81 case 's': 82 print_mask |= PRINT_SYSNAME; 83 break; 84 case 'v': 85 print_mask |= PRINT_VERSION; 86 break; 87 default: 88 usage(); 89 /* NOTREACHED */ 90 } 91 } 92 93 if (optind != argc) { 94 usage(); 95 /* NOTREACHED */ 96 } 97 98 if (!print_mask) { 99 print_mask = PRINT_SYSNAME; 100 } 101 102 if (uname(&u)) { 103 err(1, "uname"); 104 /* NOTREACHED */ 105 } 106 107 if (print_mask & PRINT_SYSNAME) { 108 space++; 109 fputs(u.sysname, stdout); 110 } 111 if (print_mask & PRINT_NODENAME) { 112 if (space++) putchar(' '); 113 fputs(u.nodename, stdout); 114 } 115 if (print_mask & PRINT_RELEASE) { 116 if (space++) putchar(' '); 117 fputs(u.release, stdout); 118 } 119 if (print_mask & PRINT_VERSION) { 120 if (space++) putchar(' '); 121 fputs(u.version, stdout); 122 } 123 if (print_mask & PRINT_MACHINE) { 124 if (space++) putchar(' '); 125 fputs(u.machine, stdout); 126 } 127 putchar('\n'); 128 129 exit(0); 130 /* NOTREACHED */ 131 } 132 133 static void 134 usage() 135 { 136 fprintf(stderr, "usage: uname [-amnrsv]\n"); 137 exit(1); 138 } 139