10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
51618Srie * Common Development and Distribution License (the "License").
61618Srie * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
211618Srie
220Sstevel@tonic-gate /*
23*6812Sraf * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
241618Srie * Use is subject to license terms.
250Sstevel@tonic-gate */
26*6812Sraf
270Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
280Sstevel@tonic-gate
29*6812Sraf #include <sys/systeminfo.h>
30*6812Sraf #include <sys/utsname.h>
31*6812Sraf #include <limits.h>
32*6812Sraf #include <strings.h>
33*6812Sraf #include "_conv.h"
340Sstevel@tonic-gate
350Sstevel@tonic-gate /*
360Sstevel@tonic-gate * Isalist(1) expansion.
370Sstevel@tonic-gate *
380Sstevel@tonic-gate * Obtain the native instruction sets executable on this platform and unpack
390Sstevel@tonic-gate * each element into the isalist descriptor.
400Sstevel@tonic-gate */
410Sstevel@tonic-gate Isa_desc *
conv_isalist(void)420Sstevel@tonic-gate conv_isalist(void)
430Sstevel@tonic-gate {
440Sstevel@tonic-gate char info[SYS_NMLN], * list, * ptr, * optr;
450Sstevel@tonic-gate Isa_desc * desc;
460Sstevel@tonic-gate Isa_opt * opt;
470Sstevel@tonic-gate long size;
480Sstevel@tonic-gate int no;
490Sstevel@tonic-gate
500Sstevel@tonic-gate if ((desc = calloc(1, sizeof (Isa_desc))) == 0)
510Sstevel@tonic-gate return (0);
520Sstevel@tonic-gate
530Sstevel@tonic-gate /*
540Sstevel@tonic-gate * If we can't get the isalist() perhaps we've gone back to a release
550Sstevel@tonic-gate * too old to support it - silently ignore.
560Sstevel@tonic-gate */
570Sstevel@tonic-gate if ((size = sysinfo(SI_ISALIST, info, SYS_NMLN)) == -1)
580Sstevel@tonic-gate return (desc);
590Sstevel@tonic-gate desc->isa_listsz = (size_t)size;
600Sstevel@tonic-gate
610Sstevel@tonic-gate /*
620Sstevel@tonic-gate * Duplicate the isalist string in preparation for breaking it up.
630Sstevel@tonic-gate */
640Sstevel@tonic-gate if ((list = strdup(info)) == 0)
650Sstevel@tonic-gate return (desc);
660Sstevel@tonic-gate desc->isa_list = list;
670Sstevel@tonic-gate
680Sstevel@tonic-gate /*
690Sstevel@tonic-gate * Determine the number of instruction sets and use this to size the
700Sstevel@tonic-gate * isalist option table.
710Sstevel@tonic-gate */
720Sstevel@tonic-gate for (no = 1, ptr = list; *ptr; ptr++) {
730Sstevel@tonic-gate if (*ptr == ' ')
740Sstevel@tonic-gate no++;
750Sstevel@tonic-gate }
760Sstevel@tonic-gate if ((opt = malloc(no * sizeof (Isa_opt))) == 0)
770Sstevel@tonic-gate return (desc);
780Sstevel@tonic-gate desc->isa_opt = opt;
790Sstevel@tonic-gate desc->isa_optno = no;
800Sstevel@tonic-gate
810Sstevel@tonic-gate /*
820Sstevel@tonic-gate * Unpack the instruction set list.
830Sstevel@tonic-gate */
840Sstevel@tonic-gate for (optr = ptr = list; *ptr; ptr++) {
850Sstevel@tonic-gate if (*ptr != ' ')
860Sstevel@tonic-gate continue;
870Sstevel@tonic-gate
880Sstevel@tonic-gate opt->isa_name = optr;
890Sstevel@tonic-gate opt->isa_namesz = ptr - optr;
900Sstevel@tonic-gate opt++;
910Sstevel@tonic-gate
920Sstevel@tonic-gate *ptr = '\0';
930Sstevel@tonic-gate optr = ptr + 1;
940Sstevel@tonic-gate }
950Sstevel@tonic-gate opt->isa_name = optr;
960Sstevel@tonic-gate opt->isa_namesz = ptr - optr;
970Sstevel@tonic-gate
980Sstevel@tonic-gate return (desc);
990Sstevel@tonic-gate }
1000Sstevel@tonic-gate
1010Sstevel@tonic-gate /*
1020Sstevel@tonic-gate * uname(2) expansion.
1030Sstevel@tonic-gate *
1040Sstevel@tonic-gate * Obtain the information that identifies the current operating system and
1050Sstevel@tonic-gate * unpack those elements we're interested in (presently name and release).
1060Sstevel@tonic-gate */
1070Sstevel@tonic-gate Uts_desc *
conv_uts(void)1080Sstevel@tonic-gate conv_uts(void)
1090Sstevel@tonic-gate {
1100Sstevel@tonic-gate struct utsname utsname;
1110Sstevel@tonic-gate Uts_desc * desc;
1120Sstevel@tonic-gate size_t size;
1130Sstevel@tonic-gate
1140Sstevel@tonic-gate if ((desc = calloc(1, sizeof (Uts_desc))) == 0)
1150Sstevel@tonic-gate return (0);
1160Sstevel@tonic-gate
1170Sstevel@tonic-gate /*
1180Sstevel@tonic-gate * If we can't get the uname(2) silently ignore.
1190Sstevel@tonic-gate */
1200Sstevel@tonic-gate if (uname(&utsname) == -1)
1210Sstevel@tonic-gate return (desc);
1220Sstevel@tonic-gate
1230Sstevel@tonic-gate /*
1240Sstevel@tonic-gate * Duplicate the operating system name and release components.
1250Sstevel@tonic-gate */
1260Sstevel@tonic-gate size = strlen(utsname.sysname);
1270Sstevel@tonic-gate if ((desc->uts_osname = malloc(size + 1)) == 0)
1280Sstevel@tonic-gate return (desc);
1290Sstevel@tonic-gate desc->uts_osnamesz = size;
1300Sstevel@tonic-gate (void) strncpy(desc->uts_osname, utsname.sysname, size);
1310Sstevel@tonic-gate
1320Sstevel@tonic-gate size = strlen(utsname.release);
1330Sstevel@tonic-gate if ((desc->uts_osrel = malloc(size + 1)) == 0)
1340Sstevel@tonic-gate return (0);
1350Sstevel@tonic-gate desc->uts_osrelsz = size;
1360Sstevel@tonic-gate (void) strncpy(desc->uts_osrel, utsname.release, size);
1370Sstevel@tonic-gate
1380Sstevel@tonic-gate return (desc);
1390Sstevel@tonic-gate }
140