4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
31 #include <fm/libtopo.h>
32 #include <fm/topo_mod.h>
33 #include <topo_alloc.h>
36 topo_hdl_strdup(topo_hdl_t
*thp
, const char *s
)
41 p
= topo_hdl_alloc(thp
, strlen(s
) + 1);
52 topo_hdl_strfree(topo_hdl_t
*thp
, char *s
)
55 topo_hdl_free(thp
, s
, strlen(s
) + 1);
59 topo_mod_strdup(topo_mod_t
*mod
, const char *s
)
61 return (topo_hdl_strdup(mod
->tm_hdl
, s
));
65 topo_mod_strfree(topo_mod_t
*mod
, char *s
)
67 topo_hdl_strfree(mod
->tm_hdl
, s
);
71 topo_strbasename(const char *s
)
73 const char *p
= strrchr(s
, '/');
82 topo_strdirname(char *s
)
84 static char slash
[] = "/";
85 static char dot
[] = ".";
88 if (s
== NULL
|| *s
== '\0')
91 for (p
= s
+ strlen(s
); p
!= s
&& *--p
== '/'; )
94 if (p
== s
&& *p
== '/')
99 while (*p
== '/' && p
!= s
)
110 topo_strhash(const char *key
)
115 for (p
= key
; *p
!= '\0'; p
++) {
118 if ((g
= (h
& 0xf0000000)) != 0) {
128 * Transform string s inline, converting each embedded C escape sequence string
129 * to the corresponding character. For example, the substring "\n" is replaced
130 * by an inline '\n' character. The length of the resulting string is returned.
133 topo_stresc2chr(char *s
)
139 for (p
= q
= s
; (c
= *p
) != '\0'; p
++) {
153 if (*p
>= '0' && *p
<= '7') {
154 c
= c
* 8 + *p
++ - '0';
156 if (*p
>= '0' && *p
<= '7')
157 c
= c
* 8 + *p
- '0';
189 for (x
= 0; (c
= *++p
) != '\0'; ) {
190 if (c
>= '0' && c
<= '9')
191 x
= x
* 16 + c
- '0';
192 else if (c
>= 'a' && c
<= 'f')
193 x
= x
* 16 + c
- 'a' + 10;
194 else if (c
>= 'A' && c
<= 'F')
195 x
= x
* 16 + c
- 'A' + 10;
215 if ((esc
= c
== '\\') == 0)
221 return ((size_t)(q
- s
));
225 topo_strmatch(const char *s
, const char *p
)
233 s
= ""; /* treat NULL string as the empty string */
236 if ((c
= *p
++) == '\0')
241 p
++; /* consecutive *'s can be collapsed */
247 if (topo_strmatch(s
++, p
) != 0)