add strdup()

This commit is contained in:
Laurent Vivier 2005-12-08 06:33:17 +00:00
parent d8bc6db8f5
commit 7a9f9c00e7
2 changed files with 21 additions and 1 deletions

View File

@ -12,7 +12,7 @@ LIBRARY = libunix.a
SOURCES = divsi3.S modsi3.S mulsi3.S udivsi3.S umodsi3.S free.c malloc.c \
memcpy.c memset.c printf.c putchar.c puts.c read.c sprintf.c \
strcpy.c strlen.c strncpy.c vsprintf.c write.c strcmp.c \
strncmp.c strtol.c
strncmp.c strtol.c strdup.c
HEADERS =

20
libunix/strdup.c Normal file
View File

@ -0,0 +1,20 @@
/*
*
* (c) 2004,2005 Laurent Vivier <LaurentVivier@wanadoo.fr>
*
*/
#include <stdlib.h>
#include <string.h>
char *strdup (__const char *__restrict __src)
{
char *__dest;
__dest = (char*)malloc(strlen(__src) + 1);
if (__dest == NULL)
return NULL;
strcpy(__dest, __src);
return __dest;
}