xref: /titanic_52/usr/src/lib/libbc/libc/sys/common/uname.c (revision 09bb53675d4f606eb5c65c3876e23280387f4fb1)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate  * Copyright 1991 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #include	<errno.h>
287c478bd9Sstevel@tonic-gate #include	<string.h>
297c478bd9Sstevel@tonic-gate #include	<sys/utsname.h>
307c478bd9Sstevel@tonic-gate #include	<sys/syscall.h>
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate /*
337c478bd9Sstevel@tonic-gate  * utsname structure has a different format in SVr4/SunOS 5.0.
347c478bd9Sstevel@tonic-gate  * The data needs to be mapped before returning to the user.
357c478bd9Sstevel@tonic-gate  */
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate /*
387c478bd9Sstevel@tonic-gate  * The following values and structure are from the SVR4 utsname.h.
397c478bd9Sstevel@tonic-gate  */
407c478bd9Sstevel@tonic-gate #define		NEW_SYS_NMLN	257
417c478bd9Sstevel@tonic-gate #define		SYS_NMLN	9
427c478bd9Sstevel@tonic-gate #define		SYS_NDLN	65
437c478bd9Sstevel@tonic-gate 
447c478bd9Sstevel@tonic-gate struct n_utsname {
457c478bd9Sstevel@tonic-gate 	char sysname[NEW_SYS_NMLN];
467c478bd9Sstevel@tonic-gate 	char nodename[NEW_SYS_NMLN];
477c478bd9Sstevel@tonic-gate 	char release[NEW_SYS_NMLN];
487c478bd9Sstevel@tonic-gate 	char version[NEW_SYS_NMLN];
497c478bd9Sstevel@tonic-gate 	char machine[NEW_SYS_NMLN];
507c478bd9Sstevel@tonic-gate };
517c478bd9Sstevel@tonic-gate 
52*09bb5367SRichard Lowe int
53*09bb5367SRichard Lowe uname(struct utsname *uts)
547c478bd9Sstevel@tonic-gate {
557c478bd9Sstevel@tonic-gate 	return (bc_uname(uts));
567c478bd9Sstevel@tonic-gate }
577c478bd9Sstevel@tonic-gate 
58*09bb5367SRichard Lowe int
59*09bb5367SRichard Lowe bc_uname(struct utsname *uts)
607c478bd9Sstevel@tonic-gate {
617c478bd9Sstevel@tonic-gate 	struct n_utsname n_uts;
627c478bd9Sstevel@tonic-gate 	int    ret;
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate 	if ((ret = _syscall(SYS_uname, &n_uts)) != -1) {
657c478bd9Sstevel@tonic-gate 		memcpy(uts->sysname, n_uts.sysname, SYS_NMLN);
667c478bd9Sstevel@tonic-gate 		if (strlen(n_uts.sysname) > SYS_NMLN)
677c478bd9Sstevel@tonic-gate 			uts->sysname[SYS_NMLN-1] = '\0';
68*09bb5367SRichard Lowe 
69*09bb5367SRichard Lowe 		/*
70*09bb5367SRichard Lowe 		 * The nodename was originally 9 bytes (including NUL), but a
71*09bb5367SRichard Lowe 		 * field was added, following it, extending it to SYS_NDLN.
72*09bb5367SRichard Lowe 		 * So we have to copy it in two passes
73*09bb5367SRichard Lowe 		 */
74*09bb5367SRichard Lowe 		memcpy(uts->nodename, n_uts.nodename, SYS_NMLN);
75*09bb5367SRichard Lowe 		memcpy(uts->nodeext, n_uts.nodename + SYS_NMLN,
76*09bb5367SRichard Lowe 		    SYS_NDLN - SYS_NMLN);
777c478bd9Sstevel@tonic-gate 		if (strlen(n_uts.nodename) > SYS_NDLN)
78*09bb5367SRichard Lowe 			uts->nodeext[sizeof (uts->nodeext) - 1] = '\0';
79*09bb5367SRichard Lowe 
807c478bd9Sstevel@tonic-gate 		memcpy(uts->release, n_uts.release, SYS_NMLN);
817c478bd9Sstevel@tonic-gate 		if (strlen(n_uts.release) > SYS_NMLN)
827c478bd9Sstevel@tonic-gate 			uts->release[SYS_NMLN-1] = '\0';
837c478bd9Sstevel@tonic-gate 		memcpy(uts->version, n_uts.version, SYS_NMLN);
847c478bd9Sstevel@tonic-gate 		if (strlen(n_uts.version) > SYS_NMLN)
857c478bd9Sstevel@tonic-gate 			uts->version[SYS_NMLN-1] = '\0';
867c478bd9Sstevel@tonic-gate 		memcpy(uts->machine, n_uts.machine, SYS_NMLN);
877c478bd9Sstevel@tonic-gate 		if (strlen(n_uts.machine) > SYS_NMLN)
887c478bd9Sstevel@tonic-gate 			uts->machine[SYS_NMLN-1] = '\0';
897c478bd9Sstevel@tonic-gate 	}
907c478bd9Sstevel@tonic-gate 
917c478bd9Sstevel@tonic-gate 	return (ret);
927c478bd9Sstevel@tonic-gate }
93