xref: /csrg-svn/lib/libc/string/strdup.c (revision 36335)
1*36335Sbostic /*
2*36335Sbostic  * Copyright (c) 1988 The Regents of the University of California.
3*36335Sbostic  * All rights reserved.
4*36335Sbostic  *
5*36335Sbostic  * Redistribution and use in source and binary forms are permitted
6*36335Sbostic  * provided that the above copyright notice and this paragraph are
7*36335Sbostic  * duplicated in all such forms and that any documentation,
8*36335Sbostic  * advertising materials, and other materials related to such
9*36335Sbostic  * distribution and use acknowledge that the software was developed
10*36335Sbostic  * by the University of California, Berkeley.  The name of the
11*36335Sbostic  * University may not be used to endorse or promote products derived
12*36335Sbostic  * from this software without specific prior written permission.
13*36335Sbostic  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14*36335Sbostic  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15*36335Sbostic  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16*36335Sbostic  */
17*36335Sbostic 
18*36335Sbostic #if defined(LIBC_SCCS) && !defined(lint)
19*36335Sbostic static char sccsid[] = "@(#)strdup.c	5.1 (Berkeley) 12/12/88";
20*36335Sbostic #endif /* LIBC_SCCS and not lint */
21*36335Sbostic 
22*36335Sbostic #include <sys/types.h>
23*36335Sbostic #include <stdio.h>
24*36335Sbostic 
25*36335Sbostic char *
26*36335Sbostic strdup(str)
27*36335Sbostic 	char *str;
28*36335Sbostic {
29*36335Sbostic 	int len;
30*36335Sbostic 	char *copy, *malloc();
31*36335Sbostic 
32*36335Sbostic 	len = strlen(str) + 1;
33*36335Sbostic 	if (!(copy = malloc((u_int)len)))
34*36335Sbostic 		return((char *)NULL);
35*36335Sbostic 	bcopy(str, copy, len);
36*36335Sbostic 	return(copy);
37*36335Sbostic }
38