xref: /titanic_41/usr/src/lib/libbc/libc/sys/common/uname.c (revision cde2885fdf538266ee2a3b08dee2d5075ce8fa2b)
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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include	<errno.h>
30 #include	<string.h>
31 #include	<sys/utsname.h>
32 #include	<sys/syscall.h>
33 
34 /*
35  * utsname structure has a different format in SVr4/SunOS 5.0.
36  * The data needs to be mapped before returning to the user.
37  */
38 
39 /*
40  * The following values and structure are from the SVR4 utsname.h.
41  */
42 #define		NEW_SYS_NMLN	257
43 #define 	SYS_NMLN	9
44 #define		SYS_NDLN	65
45 
46 struct n_utsname {
47 	char sysname[NEW_SYS_NMLN];
48 	char nodename[NEW_SYS_NMLN];
49 	char release[NEW_SYS_NMLN];
50 	char version[NEW_SYS_NMLN];
51 	char machine[NEW_SYS_NMLN];
52 };
53 
54 int uname( uts )
55 register struct utsname *uts;		/* where to put results */
56 {
57 	return(bc_uname(uts));
58 }
59 
60 int bc_uname( uts )
61 struct utsname *uts;
62 {
63 	struct n_utsname n_uts;
64 	int    ret;
65 
66 	if ((ret = _syscall(SYS_uname, &n_uts)) != -1) {
67 		memcpy(uts->sysname, n_uts.sysname, SYS_NMLN);
68 		if (strlen(n_uts.sysname) > SYS_NMLN)
69 			uts->sysname[SYS_NMLN-1] = '\0';
70 		memcpy(uts->nodename, n_uts.nodename, SYS_NDLN);
71 		if (strlen(n_uts.nodename) > SYS_NDLN)
72 			uts->nodename[SYS_NDLN-1] = '\0';
73 		memcpy(uts->release, n_uts.release, SYS_NMLN);
74 		if (strlen(n_uts.release) > SYS_NMLN)
75 			uts->release[SYS_NMLN-1] = '\0';
76 		memcpy(uts->version, n_uts.version, SYS_NMLN);
77 		if (strlen(n_uts.version) > SYS_NMLN)
78 			uts->version[SYS_NMLN-1] = '\0';
79 		memcpy(uts->machine, n_uts.machine, SYS_NMLN);
80 		if (strlen(n_uts.machine) > SYS_NMLN)
81 			uts->machine[SYS_NMLN-1] = '\0';
82 	}
83 
84 	return(ret);
85 }
86