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