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]
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #include <sys/types.h>
27 #include <sys/cmn_err.h>
28 #include <sys/systm.h>
29 #include <sys/varargs.h>
32 * SunOS-specific extensions to libc's standard set of string routines.
34 * NOTE: The standard libc string routines are in $SRC/common/util/string.c,
35 * to facilitate sharing with standalone.
39 * Historical entry point: remove in Solaris 2.8.
42 vsprintf_len(size_t buflen
, char *buf
, const char *fmt
, va_list args
)
44 (void) vsnprintf(buf
, buflen
, fmt
, args
);
49 * Historical entry point: remove in Solaris 2.8.
53 sprintf_len(size_t buflen
, char *buf
, const char *fmt
, ...)
58 (void) vsnprintf(buf
, buflen
, fmt
, args
);
65 * Simple-minded conversion of a long into a null-terminated character
66 * string. Caller must ensure there's enough space to hold the result.
69 numtos(unsigned long num
, char *s
)
76 *cp
++ = "0123456789"[num
% 10];
87 * Returns the integer value of the string of decimal numeric
88 * chars beginning at **str. Does no overflow checking.
89 * Note: updates *str to point at the last character examined.
98 for (n
= 0; (c
= *p
) >= '0' && c
<= '9'; p
++) {
106 * Like strrchr(), except
107 * (a) it takes a maximum length for the string to be searched, and
108 * (b) if the string ends with a null, it is not considered part of the string.
111 strnrchr(const char *sp
, int c
, size_t n
)
115 while (n
-- > 0 && *sp
) {
125 * NOTE: These routines aren't shared with standalone because the DDI mandates
126 * that they return the buffer rather than its length.
130 sprintf(char *buf
, const char *fmt
, ...)
135 (void) vsnprintf(buf
, INT_MAX
, fmt
, args
);
142 vsprintf(char *buf
, const char *fmt
, va_list args
)
144 (void) vsnprintf(buf
, INT_MAX
, fmt
, args
);
149 * Do not change the length of the returned string; it must be freed
153 kmem_asprintf(const char *fmt
, ...)
160 size
= vsnprintf(NULL
, 0, fmt
, adx
) + 1;
163 buf
= kmem_alloc(size
, KM_SLEEP
);
166 size
= vsnprintf(buf
, size
, fmt
, adx
);