8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / sgs / libconv / common / tokens.c
blobad114cd47e5e57c23a598566f0de250a1661e11f
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 <limits.h>
32 #include <strings.h>
33 #include "_conv.h"
36 * Isalist(1) expansion.
38 * Obtain the native instruction sets executable on this platform and unpack
39 * each element into the isalist descriptor.
41 Isa_desc *
42 conv_isalist(void)
44 char info[SYS_NMLN], * list, * ptr, * optr;
45 Isa_desc * desc;
46 Isa_opt * opt;
47 long size;
48 int no;
50 if ((desc = calloc(1, sizeof (Isa_desc))) == 0)
51 return (0);
54 * If we can't get the isalist() perhaps we've gone back to a release
55 * too old to support it - silently ignore.
57 if ((size = sysinfo(SI_ISALIST, info, SYS_NMLN)) == -1)
58 return (desc);
59 desc->isa_listsz = (size_t)size;
62 * Duplicate the isalist string in preparation for breaking it up.
64 if ((list = strdup(info)) == 0)
65 return (desc);
66 desc->isa_list = list;
69 * Determine the number of instruction sets and use this to size the
70 * isalist option table.
72 for (no = 1, ptr = list; *ptr; ptr++) {
73 if (*ptr == ' ')
74 no++;
76 if ((opt = malloc(no * sizeof (Isa_opt))) == 0)
77 return (desc);
78 desc->isa_opt = opt;
79 desc->isa_optno = no;
82 * Unpack the instruction set list.
84 for (optr = ptr = list; *ptr; ptr++) {
85 if (*ptr != ' ')
86 continue;
88 opt->isa_name = optr;
89 opt->isa_namesz = ptr - optr;
90 opt++;
92 *ptr = '\0';
93 optr = ptr + 1;
95 opt->isa_name = optr;
96 opt->isa_namesz = ptr - optr;
98 return (desc);
102 * uname(2) expansion.
104 * Obtain the information that identifies the current operating system and
105 * unpack those elements we're interested in (presently name and release).
107 Uts_desc *
108 conv_uts(void)
110 struct utsname utsname;
111 Uts_desc * desc;
112 size_t size;
114 if ((desc = calloc(1, sizeof (Uts_desc))) == 0)
115 return (0);
118 * If we can't get the uname(2) silently ignore.
120 if (uname(&utsname) == -1)
121 return (desc);
124 * Duplicate the operating system name and release components.
126 size = strlen(utsname.sysname);
127 if ((desc->uts_osname = malloc(size + 1)) == 0)
128 return (desc);
129 desc->uts_osnamesz = size;
130 (void) strncpy(desc->uts_osname, utsname.sysname, size);
132 size = strlen(utsname.release);
133 if ((desc->uts_osrel = malloc(size + 1)) == 0)
134 return (0);
135 desc->uts_osrelsz = size;
136 (void) strncpy(desc->uts_osrel, utsname.release, size);
138 return (desc);