import libssl (LibreSSL 2.5.4)
[unleashed.git] / bin / uname / uname.c
blob27ce34a06a2d06fbc82c717545b178b1e18bb564
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
22 * Copyright (c) 1988, 2010, Oracle and/or its affiliates. All rights reserved.
25 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
26 /* All Rights Reserved */
29 * University Copyright- Copyright (c) 1982, 1986, 1988
30 * The Regents of the University of California
31 * All Rights Reserved
33 * University Acknowledgment- Portions of this document are derived from
34 * software developed by the University of California, Berkeley, and its
35 * contributors.
38 #include <sys/types.h>
39 #include <stdio.h>
40 #include <stdio.h>
41 #include <string.h>
42 #include <locale.h>
43 #include <unistd.h>
44 #include <stdlib.h>
45 #include <errno.h>
46 #include <err.h>
47 #include <sys/fcntl.h>
48 #include <sys/stat.h>
49 #include <sys/utsname.h>
50 #include <sys/systeminfo.h>
52 static void usage(void);
54 /* ARGSUSED */
55 int
56 main(int argc, char *argv[], char *envp[])
58 char *nodename;
59 char *optstring = "asnrpvmiX";
60 int sflg = 0, nflg = 0, rflg = 0, vflg = 0, mflg = 0;
61 int pflg = 0, iflg = 0;
62 int errflg = 0, optlet;
63 int Xflg = 0;
64 struct utsname unstr, *un;
65 char fmt_string[] = " %.*s";
66 char *fs = &fmt_string[1];
67 char procbuf[SYS_NMLN];
69 (void) umask(~(S_IRWXU|S_IRGRP|S_IROTH) & S_IAMB);
70 un = &unstr;
71 (void) uname(un);
73 (void) setlocale(LC_ALL, "");
75 while ((optlet = getopt(argc, argv, optstring)) != EOF)
76 switch (optlet) {
77 case 'a':
78 sflg++; nflg++; rflg++; vflg++; mflg++;
79 pflg++;
80 iflg++;
81 break;
82 case 's':
83 sflg++;
84 break;
85 case 'n':
86 nflg++;
87 break;
88 case 'r':
89 rflg++;
90 break;
91 case 'v':
92 vflg++;
93 break;
94 case 'm':
95 mflg++;
96 break;
97 case 'p':
98 pflg++;
99 break;
100 case 'i':
101 iflg++;
102 break;
103 case 'X':
104 Xflg++;
105 break;
107 case '?':
108 errflg++;
111 if (errflg || (optind != argc))
112 usage();
115 * "uname -s" is the default
117 if (!(sflg || nflg || rflg || vflg || mflg || pflg || iflg || Xflg))
118 sflg++;
119 if (sflg) {
120 (void) fprintf(stdout, fs, sizeof (un->sysname),
121 un->sysname);
122 fs = fmt_string;
124 if (nflg) {
125 (void) fprintf(stdout, fs, sizeof (un->nodename), un->nodename);
126 fs = fmt_string;
128 if (rflg) {
129 (void) fprintf(stdout, fs, sizeof (un->release), un->release);
130 fs = fmt_string;
132 if (vflg) {
133 (void) fprintf(stdout, fs, sizeof (un->version), un->version);
134 fs = fmt_string;
136 if (mflg) {
137 (void) fprintf(stdout, fs, sizeof (un->machine), un->machine);
138 fs = fmt_string;
140 if (pflg) {
141 if (sysinfo(SI_ARCHITECTURE, procbuf, sizeof (procbuf)) == -1) {
142 err(1, "sysinfo");
144 (void) fprintf(stdout, fs, strlen(procbuf), procbuf);
145 fs = fmt_string;
147 if (iflg) {
148 if (sysinfo(SI_PLATFORM, procbuf, sizeof (procbuf)) == -1) {
149 err(1, "sysinfo");
151 (void) fprintf(stdout, fs, strlen(procbuf), procbuf);
152 fs = fmt_string;
154 if (sflg || nflg || rflg || vflg || mflg || pflg || iflg)
155 (void) putchar('\n');
156 if (Xflg) {
157 int val;
159 (void) fprintf(stdout, "System = %.*s\n", sizeof (un->sysname),
160 un->sysname);
161 (void) fprintf(stdout, "Node = %.*s\n", sizeof (un->nodename),
162 un->nodename);
163 (void) fprintf(stdout, "Release = %.*s\n", sizeof (un->release),
164 un->release);
165 (void) fprintf(stdout, "KernelID = %.*s\n",
166 sizeof (un->version), un->version);
167 (void) fprintf(stdout, "Machine = %.*s\n", sizeof (un->machine),
168 un->machine);
170 val = sysconf(_SC_NPROCESSORS_CONF);
171 (void) fprintf(stdout, "NumCPU = %d\n", val);
173 return (0);
176 static void
177 usage(void)
179 (void) fprintf(stderr, "usage: uname [-snrvmapiX]\n");
180 exit(1);