xref: /titanic_41/usr/src/lib/libbc/libc/sys/common/uname.c (revision c037192b037119c9fd354732fc29b38ce097d356)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 1991 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #include	<errno.h>
28 #include	<string.h>
29 #include	<sys/utsname.h>
30 #include	<sys/syscall.h>
31 
32 /*
33  * utsname structure has a different format in SVr4/SunOS 5.0.
34  * The data needs to be mapped before returning to the user.
35  */
36 
37 /*
38  * The following values and structure are from the SVR4 utsname.h.
39  */
40 #define		NEW_SYS_NMLN	257
41 #define		SYS_NMLN	9
42 #define		SYS_NDLN	65
43 
44 struct n_utsname {
45 	char sysname[NEW_SYS_NMLN];
46 	char nodename[NEW_SYS_NMLN];
47 	char release[NEW_SYS_NMLN];
48 	char version[NEW_SYS_NMLN];
49 	char machine[NEW_SYS_NMLN];
50 };
51 
52 int
53 uname(struct utsname *uts)
54 {
55 	return (bc_uname(uts));
56 }
57 
58 int
59 bc_uname(struct utsname *uts)
60 {
61 	struct n_utsname n_uts;
62 	int    ret;
63 
64 	if ((ret = _syscall(SYS_uname, &n_uts)) != -1) {
65 		memcpy(uts->sysname, n_uts.sysname, SYS_NMLN);
66 		if (strlen(n_uts.sysname) > SYS_NMLN)
67 			uts->sysname[SYS_NMLN-1] = '\0';
68 
69 		/*
70 		 * The nodename was originally 9 bytes (including NUL), but a
71 		 * field was added, following it, extending it to SYS_NDLN.
72 		 * So we have to copy it in two passes
73 		 */
74 		memcpy(uts->nodename, n_uts.nodename, SYS_NMLN);
75 		memcpy(uts->nodeext, n_uts.nodename + SYS_NMLN,
76 		    SYS_NDLN - SYS_NMLN);
77 		if (strlen(n_uts.nodename) > SYS_NDLN)
78 			uts->nodeext[sizeof (uts->nodeext) - 1] = '\0';
79 
80 		memcpy(uts->release, n_uts.release, SYS_NMLN);
81 		if (strlen(n_uts.release) > SYS_NMLN)
82 			uts->release[SYS_NMLN-1] = '\0';
83 		memcpy(uts->version, n_uts.version, SYS_NMLN);
84 		if (strlen(n_uts.version) > SYS_NMLN)
85 			uts->version[SYS_NMLN-1] = '\0';
86 		memcpy(uts->machine, n_uts.machine, SYS_NMLN);
87 		if (strlen(n_uts.machine) > SYS_NMLN)
88 			uts->machine[SYS_NMLN-1] = '\0';
89 	}
90 
91 	return (ret);
92 }
93