xref: /original-bsd/lib/libc/string/strdup.c (revision 0a33e010)
1 /*
2  * Copyright (c) 1988 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  */
7 
8 #if defined(LIBC_SCCS) && !defined(lint)
9 static char sccsid[] = "@(#)strdup.c	5.3 (Berkeley) 06/01/90";
10 #endif /* LIBC_SCCS and not lint */
11 
12 #include <sys/types.h>
13 #include <stddef.h>
14 #include <string.h>
15 
16 
17 char *
18 strdup(str)
19 	char *str;
20 {
21 	int len;
22 	char *copy, *malloc();
23 
24 	len = strlen(str) + 1;
25 	if (!(copy = malloc((u_int)len)))
26 		return((char *)NULL);
27 	bcopy(str, copy, len);
28 	return(copy);
29 }
30