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