ncurses: move headers to /usr/include
[unleashed.git] / bin / uname / uname.c
blob0413dac56a1e5dfb56613c4377d224e7dcd38771
1 /* $OpenBSD: uname.c,v 1.19 2016/10/28 07:22:59 schwarze Exp $ */
3 /*
4 * Copyright (c) 1994 Winning Strategies, Inc.
5 * All rights reserved.
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.
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.
34 #include <sys/utsname.h>
35 #include <sys/systeminfo.h>
37 #include <err.h>
38 #include <stdio.h>
39 #include <stdlib.h>
40 #include <unistd.h>
42 #define __dead __attribute__((__noreturn__))
43 #define pledge(request, paths) 0
44 static void __dead usage(void);
46 #define PRINT_SYSNAME 0x01
47 #define PRINT_NODENAME 0x02
48 #define PRINT_RELEASE 0x04
49 #define PRINT_VERSION 0x08
50 #define PRINT_MACHINE 0x10
51 #define PRINT_ALL 0x1f
52 #define PRINT_MACHINE_ARCH 0x20
54 int
55 main(int argc, char *argv[])
57 struct utsname u;
58 int c;
59 int space = 0;
60 int print_mask = 0;
62 if (pledge("stdio", NULL) == -1)
63 err(1, "pledge");
65 while ((c = getopt(argc, argv, "amnrsvp")) != -1 ) {
66 switch (c) {
67 case 'a':
68 print_mask |= PRINT_ALL;
69 break;
70 case 'm':
71 print_mask |= PRINT_MACHINE;
72 break;
73 case 'n':
74 print_mask |= PRINT_NODENAME;
75 break;
76 case 'p':
77 print_mask |= PRINT_MACHINE_ARCH;
78 break;
79 case 'r':
80 print_mask |= PRINT_RELEASE;
81 break;
82 case 's':
83 print_mask |= PRINT_SYSNAME;
84 break;
85 case 'v':
86 print_mask |= PRINT_VERSION;
87 break;
88 default:
89 usage();
93 if (optind != argc)
94 usage();
96 if (!print_mask)
97 print_mask = PRINT_SYSNAME;
99 if (uname(&u) == -1)
100 err(1, NULL);
102 if (print_mask & PRINT_SYSNAME) {
103 space++;
104 fputs(u.sysname, stdout);
106 if (print_mask & PRINT_NODENAME) {
107 if (space++)
108 putchar(' ');
110 fputs(u.nodename, stdout);
112 if (print_mask & PRINT_RELEASE) {
113 if (space++)
114 putchar(' ');
116 fputs(u.release, stdout);
118 if (print_mask & PRINT_VERSION) {
119 if (space++)
120 putchar(' ');
122 fputs(u.version, stdout);
124 if (print_mask & PRINT_MACHINE) {
125 if (space++)
126 putchar(' ');
128 fputs(u.machine, stdout);
130 if (print_mask & PRINT_MACHINE_ARCH) {
131 if (space++)
132 putchar(' ');
134 char buf[SYS_NMLN];
135 if (sysinfo(SI_ARCHITECTURE, buf, SYS_NMLN) < 0)
136 err(1, "sysinfo");
137 fputs(buf, stdout);
139 putchar('\n');
141 return 0;
144 static void __dead
145 usage(void)
147 fprintf(stderr, "usage: uname [-amnprsv]\n");
148 exit(1);