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]
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
33 * University Acknowledgment- Portions of this document are derived from
34 * software developed by the University of California, Berkeley, and its
38 #include <sys/types.h>
47 #include <sys/fcntl.h>
49 #include <sys/utsname.h>
50 #include <sys/systeminfo.h>
52 static void usage(void);
56 main(int argc
, char *argv
[], char *envp
[])
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
;
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
);
73 (void) setlocale(LC_ALL
, "");
75 while ((optlet
= getopt(argc
, argv
, optstring
)) != EOF
)
78 sflg
++; nflg
++; rflg
++; vflg
++; mflg
++;
111 if (errflg
|| (optind
!= argc
))
115 * "uname -s" is the default
117 if (!(sflg
|| nflg
|| rflg
|| vflg
|| mflg
|| pflg
|| iflg
|| Xflg
))
120 (void) fprintf(stdout
, fs
, sizeof (un
->sysname
),
125 (void) fprintf(stdout
, fs
, sizeof (un
->nodename
), un
->nodename
);
129 (void) fprintf(stdout
, fs
, sizeof (un
->release
), un
->release
);
133 (void) fprintf(stdout
, fs
, sizeof (un
->version
), un
->version
);
137 (void) fprintf(stdout
, fs
, sizeof (un
->machine
), un
->machine
);
141 if (sysinfo(SI_ARCHITECTURE
, procbuf
, sizeof (procbuf
)) == -1) {
144 (void) fprintf(stdout
, fs
, strlen(procbuf
), procbuf
);
148 if (sysinfo(SI_PLATFORM
, procbuf
, sizeof (procbuf
)) == -1) {
151 (void) fprintf(stdout
, fs
, strlen(procbuf
), procbuf
);
154 if (sflg
|| nflg
|| rflg
|| vflg
|| mflg
|| pflg
|| iflg
)
155 (void) putchar('\n');
159 (void) fprintf(stdout
, "System = %.*s\n", sizeof (un
->sysname
),
161 (void) fprintf(stdout
, "Node = %.*s\n", sizeof (un
->nodename
),
163 (void) fprintf(stdout
, "Release = %.*s\n", sizeof (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
),
170 val
= sysconf(_SC_NPROCESSORS_CONF
);
171 (void) fprintf(stdout
, "NumCPU = %d\n", val
);
179 (void) fprintf(stderr
, "usage: uname [-snrvmapiX]\n");