xref: /netbsd/sys/arch/ia64/stand/common/strdup.c (revision 93b81f4c)
1*93b81f4cSkiyohara /*	$NetBSD: strdup.c,v 1.3 2009/07/20 04:59:03 kiyohara Exp $	*/
2ba7cbe76Scherry 
3ba7cbe76Scherry /*
4ba7cbe76Scherry  * Copyright (c) 1988, 1993
5ba7cbe76Scherry  *	The Regents of the University of California.  All rights reserved.
6ba7cbe76Scherry  *
7ba7cbe76Scherry  * Redistribution and use in source and binary forms, with or without
8ba7cbe76Scherry  * modification, are permitted provided that the following conditions
9ba7cbe76Scherry  * are met:
10ba7cbe76Scherry  * 1. Redistributions of source code must retain the above copyright
11ba7cbe76Scherry  *    notice, this list of conditions and the following disclaimer.
12ba7cbe76Scherry  * 2. Redistributions in binary form must reproduce the above copyright
13ba7cbe76Scherry  *    notice, this list of conditions and the following disclaimer in the
14ba7cbe76Scherry  *    documentation and/or other materials provided with the distribution.
15ba7cbe76Scherry  * 3. All advertising materials mentioning features or use of this software
16ba7cbe76Scherry  *    must display the following acknowledgement:
17ba7cbe76Scherry  *	This product includes software developed by the University of
18ba7cbe76Scherry  *	California, Berkeley and its contributors.
19ba7cbe76Scherry  * 4. Neither the name of the University nor the names of its contributors
20ba7cbe76Scherry  *    may be used to endorse or promote products derived from this software
21ba7cbe76Scherry  *    without specific prior written permission.
22ba7cbe76Scherry  *
23ba7cbe76Scherry  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24ba7cbe76Scherry  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25ba7cbe76Scherry  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26ba7cbe76Scherry  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27ba7cbe76Scherry  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28ba7cbe76Scherry  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29ba7cbe76Scherry  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30ba7cbe76Scherry  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31ba7cbe76Scherry  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32ba7cbe76Scherry  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33ba7cbe76Scherry  * SUCH DAMAGE.
34ba7cbe76Scherry  */
35ba7cbe76Scherry 
36ba7cbe76Scherry #include <sys/cdefs.h>
37ba7cbe76Scherry 
38ba7cbe76Scherry #if defined(LIBC_SCCS) && !defined(lint)
39ba7cbe76Scherry static char sccsid[] = "@(#)strdup.c	8.1 (Berkeley) 6/4/93";
40ba7cbe76Scherry #endif /* LIBC_SCCS and not lint */
41ba7cbe76Scherry 
42ba7cbe76Scherry #include <lib/libsa/stand.h>
43*93b81f4cSkiyohara #include <lib/libsa/loadfile.h>
44ba7cbe76Scherry #include <lib/libkern/libkern.h>
45ba7cbe76Scherry 
46ba7cbe76Scherry #include "bootstrap.h"
47ba7cbe76Scherry 
48ba7cbe76Scherry 
49ba7cbe76Scherry char *
strdup(const char * str)50454af1c0Sdsl strdup(const char *str)
51ba7cbe76Scherry {
52ba7cbe76Scherry 	size_t len;
53ba7cbe76Scherry 	char *copy = NULL;
54ba7cbe76Scherry 
55ba7cbe76Scherry 	if (str != NULL) {
56ba7cbe76Scherry 	    len = strlen(str) + 1;
57ba7cbe76Scherry 	    if ((copy = alloc(len)) == NULL)
58ba7cbe76Scherry 		return (NULL);
59ba7cbe76Scherry 	    memcpy(copy, str, len);
60ba7cbe76Scherry 	}
61ba7cbe76Scherry 	return (copy);
62ba7cbe76Scherry }
63