xref: /onnv-gate/usr/src/cmd/filebench/common/utils.c (revision 6613:38664cf1a8a1)
1 /*
2  * CDDL HEADER START
3  *
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.
7  *
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.
12  *
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]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  *
25  * Portions Copyright 2008 Denis Cheng
26  */
27 
28 #pragma ident	"%Z%%M%	%I%	%E% SMI"
29 
30 #include <limits.h>
31 #include <string.h>
32 #include <stdlib.h>
33 #include <stdarg.h>
34 #include <stdio.h>
35 #include <errno.h>
36 #ifdef HAVE_STDINT_H
37 #include <stdint.h>
38 #endif
39 
40 #include "filebench.h"
41 #include "utils.h"
42 #include "parsertypes.h"
43 
44 /*
45  * For now, just two routines: one to allocate a string in shared
46  * memory, and one to get the final file or directory name from a
47  * supplied pathname.
48  *
49  */
50 
51 
52 /*
53  * Allocates space for a new string of the same length as
54  * the supplied string "str". Copies the old string into
55  * the new string and returns a pointer to the new string.
56  * Returns NULL if memory allocation for the new string fails.
57  */
58 char *
59 fb_stralloc(char *str)
60 {
61 	char *newstr;
62 
63 	if ((newstr = malloc(strlen(str) + 1)) == NULL)
64 		return (NULL);
65 	(void) strcpy(newstr, str);
66 	return (newstr);
67 }
68