]>
Commit | Line | Data |
---|---|---|
44bd5ea7 A |
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 <stdlib.h> | |
41 | #include <string.h> | |
42 | #include <locale.h> | |
43 | #include <unistd.h> | |
44 | #include <sys/utsname.h> | |
45 | #include <err.h> | |
46 | ||
47 | int main __P((int, char **)); | |
48 | static void usage __P((void)); | |
49 | ||
50 | #define PRINT_SYSNAME 0x01 | |
51 | #define PRINT_NODENAME 0x02 | |
52 | #define PRINT_RELEASE 0x04 | |
53 | #define PRINT_VERSION 0x08 | |
54 | #define PRINT_MACHINE 0x10 | |
55 | #define PRINT_PROCESSOR 0x20 | |
56 | #define PRINT_ALL 0x3f | |
57 | ||
58 | int | |
59 | main(argc, argv) | |
60 | int argc; | |
61 | char **argv; | |
62 | { | |
63 | struct utsname u; | |
64 | int c; | |
65 | int space = 0; | |
66 | int print_mask = 0; | |
67 | ||
68 | setlocale(LC_ALL, ""); | |
69 | ||
70 | while ((c = getopt(argc,argv,"amnprsv")) != -1 ) { | |
71 | switch ( c ) { | |
72 | case 'a': | |
73 | print_mask |= PRINT_ALL; | |
74 | break; | |
75 | case 'm': | |
76 | print_mask |= PRINT_MACHINE; | |
77 | break; | |
78 | case 'n': | |
79 | print_mask |= PRINT_NODENAME; | |
80 | break; | |
81 | case 'p': | |
82 | print_mask |= PRINT_PROCESSOR; | |
83 | break; | |
84 | case 'r': | |
85 | print_mask |= PRINT_RELEASE; | |
86 | break; | |
87 | case 's': | |
88 | print_mask |= PRINT_SYSNAME; | |
89 | break; | |
90 | case 'v': | |
91 | print_mask |= PRINT_VERSION; | |
92 | break; | |
93 | default: | |
94 | usage(); | |
95 | /* NOTREACHED */ | |
96 | } | |
97 | } | |
98 | ||
99 | if (optind != argc) { | |
100 | usage(); | |
101 | /* NOTREACHED */ | |
102 | } | |
103 | ||
104 | if (!print_mask) { | |
105 | print_mask = PRINT_SYSNAME; | |
106 | } | |
107 | ||
108 | if (uname(&u)) { | |
109 | err(1, "uname"); | |
110 | /* NOTREACHED */ | |
111 | } | |
112 | ||
113 | /* | |
114 | * Let's allow the user to override the output of uname via the shell environment. | |
115 | * This is a useful feature for cross-compiling (eg. during an OS bringup). | |
116 | * Otherwise, you have to hack your kernel with the desired strings. | |
117 | */ | |
118 | { | |
119 | char *s; | |
120 | s = getenv ("UNAME_SYSNAME"); if (s) strncpy (u.sysname, s, sizeof (u.sysname)); | |
121 | s = getenv ("UNAME_NODENAME"); if (s) strncpy (u.nodename, s, sizeof (u.nodename)); | |
122 | s = getenv ("UNAME_RELEASE"); if (s) strncpy (u.release, s, sizeof (u.release)); | |
123 | s = getenv ("UNAME_VERSION"); if (s) strncpy (u.version, s, sizeof (u.version)); | |
124 | s = getenv ("UNAME_MACHINE"); if (s) strncpy (u.machine, s, sizeof (u.machine)); | |
125 | } | |
126 | ||
127 | if (print_mask & PRINT_SYSNAME) { | |
128 | space++; | |
129 | fputs(u.sysname, stdout); | |
130 | } | |
131 | if (print_mask & PRINT_NODENAME) { | |
132 | if (space++) putchar(' '); | |
133 | fputs(u.nodename, stdout); | |
134 | } | |
135 | if (print_mask & PRINT_RELEASE) { | |
136 | if (space++) putchar(' '); | |
137 | fputs(u.release, stdout); | |
138 | } | |
139 | if (print_mask & PRINT_VERSION) { | |
140 | if (space++) putchar(' '); | |
141 | fputs(u.version, stdout); | |
142 | } | |
143 | if (print_mask & PRINT_MACHINE) { | |
144 | if (space++) putchar(' '); | |
145 | fputs(u.machine, stdout); | |
146 | } | |
147 | if (print_mask & PRINT_PROCESSOR) { | |
148 | if (space++) putchar(' '); | |
149 | #if defined(__ppc__) | |
150 | fputs("powerpc", stdout); | |
151 | #elif defined(__i386__) | |
152 | fputs("i386", stdout); | |
153 | #else | |
154 | fputs("unknown", stdout); | |
155 | #endif | |
156 | } | |
157 | putchar('\n'); | |
158 | ||
159 | exit(0); | |
160 | /* NOTREACHED */ | |
161 | } | |
162 | ||
163 | static void | |
164 | usage() | |
165 | { | |
166 | fprintf(stderr, "usage: uname [-amnprsv]\n"); | |
167 | exit(1); | |
168 | } |