1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <sys/systeminfo.h>
#include <sys/utsname.h>
#include <limits.h>
#include <strings.h>
#include "_conv.h"
/*
* Isalist(1) expansion.
*
* Obtain the native instruction sets executable on this platform and unpack
* each element into the isalist descriptor.
*/
Isa_desc *
conv_isalist(void)
{
char info[SYS_NMLN], * list, * ptr, * optr;
Isa_desc * desc;
Isa_opt * opt;
long size;
int no;
if ((desc = calloc(1, sizeof (Isa_desc))) == 0)
return (0);
/*
* If we can't get the isalist() perhaps we've gone back to a release
* too old to support it - silently ignore.
*/
if ((size = sysinfo(SI_ISALIST, info, SYS_NMLN)) == -1)
return (desc);
desc->isa_listsz = (size_t)size;
/*
* Duplicate the isalist string in preparation for breaking it up.
*/
if ((list = strdup(info)) == 0)
return (desc);
desc->isa_list = list;
/*
* Determine the number of instruction sets and use this to size the
* isalist option table.
*/
for (no = 1, ptr = list; *ptr; ptr++) {
if (*ptr == ' ')
no++;
}
if ((opt = malloc(no * sizeof (Isa_opt))) == 0)
return (desc);
desc->isa_opt = opt;
desc->isa_optno = no;
/*
* Unpack the instruction set list.
*/
for (optr = ptr = list; *ptr; ptr++) {
if (*ptr != ' ')
continue;
opt->isa_name = optr;
opt->isa_namesz = ptr - optr;
opt++;
*ptr = '\0';
optr = ptr + 1;
}
opt->isa_name = optr;
opt->isa_namesz = ptr - optr;
return (desc);
}
/*
* uname(2) expansion.
*
* Obtain the information that identifies the current operating system and
* unpack those elements we're interested in (presently name and release).
*/
Uts_desc *
conv_uts(void)
{
struct utsname utsname;
Uts_desc * desc;
size_t size;
if ((desc = calloc(1, sizeof (Uts_desc))) == 0)
return (0);
/*
* If we can't get the uname(2) silently ignore.
*/
if (uname(&utsname) == -1)
return (desc);
/*
* Duplicate the operating system name and release components.
*/
size = strlen(utsname.sysname);
if ((desc->uts_osname = malloc(size + 1)) == 0)
return (desc);
desc->uts_osnamesz = size;
(void) strncpy(desc->uts_osname, utsname.sysname, size);
size = strlen(utsname.release);
if ((desc->uts_osrel = malloc(size + 1)) == 0)
return (0);
desc->uts_osrelsz = size;
(void) strncpy(desc->uts_osrel, utsname.release, size);
return (desc);
}
|