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