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 (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
25 #include "libuutil_common.h"
38 uu_set_error(UU_ERROR_SYSTEM
);
42 (void) memset(p
, 0, n
);
54 uu_strdup(const char *str
)
64 (void) memcpy(buf
, str
, sz
);
70 * Duplicate up to n bytes of a string. Kind of sort of like
71 * strdup(strlcpy(s, n)).
74 uu_strndup(const char *s
, size_t n
)
80 p
= uu_zalloc(len
+ 1);
85 (void) memcpy(p
, s
, len
);
92 * Duplicate a block of memory. Combines malloc with memcpy, much as
93 * strdup combines malloc, strlen, and strcpy.
96 uu_memdup(const void *buf
, size_t sz
)
103 (void) memcpy(p
, buf
, sz
);
108 uu_msprintf(const char *format
, ...)
115 va_start(args
, format
);
116 M
= vsnprintf(attic
, 1, format
, args
);
121 if ((b
= uu_zalloc(m
+ 1)) == NULL
)
124 va_start(args
, format
);
125 M
= vsnprintf(b
, m
+ 1, format
, args
);
129 break; /* sizes match */