usr/src/uts/common/os/strext.c
changeset 10272 a0669934e974
parent 0 68f95e015346
equal deleted inserted replaced
10271:7c80b70bb8de 10272:a0669934e974
     1 /*
     1 /*
     2  * CDDL HEADER START
     2  * CDDL HEADER START
     3  *
     3  *
     4  * The contents of this file are subject to the terms of the
     4  * The contents of this file are subject to the terms of the
     5  * Common Development and Distribution License, Version 1.0 only
     5  * Common Development and Distribution License (the "License").
     6  * (the "License").  You may not use this file except in compliance
     6  * You may not use this file except in compliance with the License.
     7  * with the License.
       
     8  *
     7  *
     9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
     8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
    10  * or http://www.opensolaris.org/os/licensing.
     9  * or http://www.opensolaris.org/os/licensing.
    11  * See the License for the specific language governing permissions
    10  * See the License for the specific language governing permissions
    12  * and limitations under the License.
    11  * and limitations under the License.
    18  * information: Portions Copyright [yyyy] [name of copyright owner]
    17  * information: Portions Copyright [yyyy] [name of copyright owner]
    19  *
    18  *
    20  * CDDL HEADER END
    19  * CDDL HEADER END
    21  */
    20  */
    22 /*
    21 /*
    23  * Copyright 1998-2003 Sun Microsystems, Inc.  All rights reserved.
    22  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
    24  * Use is subject to license terms.
    23  * Use is subject to license terms.
    25  */
    24  */
    26 
       
    27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
       
    28 
    25 
    29 #include <sys/types.h>
    26 #include <sys/types.h>
    30 #include <sys/cmn_err.h>
    27 #include <sys/cmn_err.h>
    31 #include <sys/systm.h>
    28 #include <sys/systm.h>
    32 #include <sys/varargs.h>
    29 #include <sys/varargs.h>
   145 vsprintf(char *buf, const char *fmt, va_list args)
   142 vsprintf(char *buf, const char *fmt, va_list args)
   146 {
   143 {
   147 	(void) vsnprintf(buf, INT_MAX, fmt, args);
   144 	(void) vsnprintf(buf, INT_MAX, fmt, args);
   148 	return (buf);
   145 	return (buf);
   149 }
   146 }
       
   147 
       
   148 /*
       
   149  * Do not change the length of the returned string; it must be freed
       
   150  * with strfree().
       
   151  */
       
   152 char *
       
   153 kmem_asprintf(const char *fmt, ...)
       
   154 {
       
   155 	int size;
       
   156 	va_list adx;
       
   157 	char *buf;
       
   158 
       
   159 	va_start(adx, fmt);
       
   160 	size = vsnprintf(NULL, 0, fmt, adx) + 1;
       
   161 	va_end(adx);
       
   162 
       
   163 	buf = kmem_alloc(size, KM_SLEEP);
       
   164 
       
   165 	va_start(adx, fmt);
       
   166 	size = vsnprintf(buf, size, fmt, adx);
       
   167 	va_end(adx);
       
   168 
       
   169 	return (buf);
       
   170 }