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
55aefb655Srie * Common Development and Distribution License (the "License").
65aefb655Srie * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
215aefb655Srie
227c478bd9Sstevel@tonic-gate /*
23*7257d1b4Sraf * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
245aefb655Srie * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate */
267c478bd9Sstevel@tonic-gate
27*7257d1b4Sraf #pragma ident "%Z%%M% %I% %E% SMI"
287c478bd9Sstevel@tonic-gate
297c478bd9Sstevel@tonic-gate #include <sys/systeminfo.h>
307c478bd9Sstevel@tonic-gate #include <sys/utsname.h>
317c478bd9Sstevel@tonic-gate #include <limits.h>
327c478bd9Sstevel@tonic-gate #include <strings.h>
337c478bd9Sstevel@tonic-gate #include "_conv.h"
347c478bd9Sstevel@tonic-gate
357c478bd9Sstevel@tonic-gate /*
367c478bd9Sstevel@tonic-gate * Isalist(1) expansion.
377c478bd9Sstevel@tonic-gate *
387c478bd9Sstevel@tonic-gate * Obtain the native instruction sets executable on this platform and unpack
397c478bd9Sstevel@tonic-gate * each element into the isalist descriptor.
407c478bd9Sstevel@tonic-gate */
417c478bd9Sstevel@tonic-gate Isa_desc *
conv_isalist(void)427c478bd9Sstevel@tonic-gate conv_isalist(void)
437c478bd9Sstevel@tonic-gate {
447c478bd9Sstevel@tonic-gate char info[SYS_NMLN], * list, * ptr, * optr;
457c478bd9Sstevel@tonic-gate Isa_desc * desc;
467c478bd9Sstevel@tonic-gate Isa_opt * opt;
477c478bd9Sstevel@tonic-gate long size;
487c478bd9Sstevel@tonic-gate int no;
497c478bd9Sstevel@tonic-gate
507c478bd9Sstevel@tonic-gate if ((desc = calloc(1, sizeof (Isa_desc))) == 0)
517c478bd9Sstevel@tonic-gate return (0);
527c478bd9Sstevel@tonic-gate
537c478bd9Sstevel@tonic-gate /*
547c478bd9Sstevel@tonic-gate * If we can't get the isalist() perhaps we've gone back to a release
557c478bd9Sstevel@tonic-gate * too old to support it - silently ignore.
567c478bd9Sstevel@tonic-gate */
577c478bd9Sstevel@tonic-gate if ((size = sysinfo(SI_ISALIST, info, SYS_NMLN)) == -1)
587c478bd9Sstevel@tonic-gate return (desc);
597c478bd9Sstevel@tonic-gate desc->isa_listsz = (size_t)size;
607c478bd9Sstevel@tonic-gate
617c478bd9Sstevel@tonic-gate /*
627c478bd9Sstevel@tonic-gate * Duplicate the isalist string in preparation for breaking it up.
637c478bd9Sstevel@tonic-gate */
647c478bd9Sstevel@tonic-gate if ((list = strdup(info)) == 0)
657c478bd9Sstevel@tonic-gate return (desc);
667c478bd9Sstevel@tonic-gate desc->isa_list = list;
677c478bd9Sstevel@tonic-gate
687c478bd9Sstevel@tonic-gate /*
697c478bd9Sstevel@tonic-gate * Determine the number of instruction sets and use this to size the
707c478bd9Sstevel@tonic-gate * isalist option table.
717c478bd9Sstevel@tonic-gate */
727c478bd9Sstevel@tonic-gate for (no = 1, ptr = list; *ptr; ptr++) {
737c478bd9Sstevel@tonic-gate if (*ptr == ' ')
747c478bd9Sstevel@tonic-gate no++;
757c478bd9Sstevel@tonic-gate }
767c478bd9Sstevel@tonic-gate if ((opt = malloc(no * sizeof (Isa_opt))) == 0)
777c478bd9Sstevel@tonic-gate return (desc);
787c478bd9Sstevel@tonic-gate desc->isa_opt = opt;
797c478bd9Sstevel@tonic-gate desc->isa_optno = no;
807c478bd9Sstevel@tonic-gate
817c478bd9Sstevel@tonic-gate /*
827c478bd9Sstevel@tonic-gate * Unpack the instruction set list.
837c478bd9Sstevel@tonic-gate */
847c478bd9Sstevel@tonic-gate for (optr = ptr = list; *ptr; ptr++) {
857c478bd9Sstevel@tonic-gate if (*ptr != ' ')
867c478bd9Sstevel@tonic-gate continue;
877c478bd9Sstevel@tonic-gate
887c478bd9Sstevel@tonic-gate opt->isa_name = optr;
897c478bd9Sstevel@tonic-gate opt->isa_namesz = ptr - optr;
907c478bd9Sstevel@tonic-gate opt++;
917c478bd9Sstevel@tonic-gate
927c478bd9Sstevel@tonic-gate *ptr = '\0';
937c478bd9Sstevel@tonic-gate optr = ptr + 1;
947c478bd9Sstevel@tonic-gate }
957c478bd9Sstevel@tonic-gate opt->isa_name = optr;
967c478bd9Sstevel@tonic-gate opt->isa_namesz = ptr - optr;
977c478bd9Sstevel@tonic-gate
987c478bd9Sstevel@tonic-gate return (desc);
997c478bd9Sstevel@tonic-gate }
1007c478bd9Sstevel@tonic-gate
1017c478bd9Sstevel@tonic-gate /*
1027c478bd9Sstevel@tonic-gate * uname(2) expansion.
1037c478bd9Sstevel@tonic-gate *
1047c478bd9Sstevel@tonic-gate * Obtain the information that identifies the current operating system and
1057c478bd9Sstevel@tonic-gate * unpack those elements we're interested in (presently name and release).
1067c478bd9Sstevel@tonic-gate */
1077c478bd9Sstevel@tonic-gate Uts_desc *
conv_uts(void)1087c478bd9Sstevel@tonic-gate conv_uts(void)
1097c478bd9Sstevel@tonic-gate {
1107c478bd9Sstevel@tonic-gate struct utsname utsname;
1117c478bd9Sstevel@tonic-gate Uts_desc * desc;
1127c478bd9Sstevel@tonic-gate size_t size;
1137c478bd9Sstevel@tonic-gate
1147c478bd9Sstevel@tonic-gate if ((desc = calloc(1, sizeof (Uts_desc))) == 0)
1157c478bd9Sstevel@tonic-gate return (0);
1167c478bd9Sstevel@tonic-gate
1177c478bd9Sstevel@tonic-gate /*
1187c478bd9Sstevel@tonic-gate * If we can't get the uname(2) silently ignore.
1197c478bd9Sstevel@tonic-gate */
1207c478bd9Sstevel@tonic-gate if (uname(&utsname) == -1)
1217c478bd9Sstevel@tonic-gate return (desc);
1227c478bd9Sstevel@tonic-gate
1237c478bd9Sstevel@tonic-gate /*
1247c478bd9Sstevel@tonic-gate * Duplicate the operating system name and release components.
1257c478bd9Sstevel@tonic-gate */
1267c478bd9Sstevel@tonic-gate size = strlen(utsname.sysname);
1277c478bd9Sstevel@tonic-gate if ((desc->uts_osname = malloc(size + 1)) == 0)
1287c478bd9Sstevel@tonic-gate return (desc);
1297c478bd9Sstevel@tonic-gate desc->uts_osnamesz = size;
1307c478bd9Sstevel@tonic-gate (void) strncpy(desc->uts_osname, utsname.sysname, size);
1317c478bd9Sstevel@tonic-gate
1327c478bd9Sstevel@tonic-gate size = strlen(utsname.release);
1337c478bd9Sstevel@tonic-gate if ((desc->uts_osrel = malloc(size + 1)) == 0)
1347c478bd9Sstevel@tonic-gate return (0);
1357c478bd9Sstevel@tonic-gate desc->uts_osrelsz = size;
1367c478bd9Sstevel@tonic-gate (void) strncpy(desc->uts_osrel, utsname.release, size);
1377c478bd9Sstevel@tonic-gate
1387c478bd9Sstevel@tonic-gate return (desc);
1397c478bd9Sstevel@tonic-gate }
140