Add include files to get prototype declarations, and fix bugs found.
[unix-history] / usr / src / lib / libc / string / strdup.c
CommitLineData
4a5f8f09
KB
1/*
2 * Copyright (c) 1988 The Regents of the University of California.
3 * All rights reserved.
4 *
019bea33 5 * %sccs.include.redist.c%
4a5f8f09
KB
6 */
7
8#if defined(LIBC_SCCS) && !defined(lint)
46b5f26a 9static char sccsid[] = "@(#)strdup.c 5.4 (Berkeley) %G%";
4a5f8f09
KB
10#endif /* LIBC_SCCS and not lint */
11
336401ac 12#include <stddef.h>
46b5f26a 13#include <stdlib.h>
336401ac
KB
14#include <string.h>
15
4a5f8f09
KB
16char *
17strdup(str)
46b5f26a 18 const char *str;
4a5f8f09
KB
19{
20 int len;
46b5f26a 21 char *copy;
4a5f8f09
KB
22
23 len = strlen(str) + 1;
24 if (!(copy = malloc((u_int)len)))
25 return((char *)NULL);
26 bcopy(str, copy, len);
27 return(copy);
28}