From e611b132f9b8abe35b362e5870b74bce94a1e58e Mon Sep 17 00:00:00 2001 From: Adam Date: Sat, 16 May 2020 20:51:50 -0700 Subject: initial commit --- private/crt32/string/strdup.c | 60 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 private/crt32/string/strdup.c (limited to 'private/crt32/string/strdup.c') diff --git a/private/crt32/string/strdup.c b/private/crt32/string/strdup.c new file mode 100644 index 000000000..2e15d16cd --- /dev/null +++ b/private/crt32/string/strdup.c @@ -0,0 +1,60 @@ +/*** +*strdup.c - duplicate a string in malloc'd memory +* +* Copyright (c) 1985-1991, Microsoft Corporation. All rights reserved. +* +*Purpose: +* defines _strdup() - grab new memory, and duplicate the string into it. +* +*Revision History: +* 05-31-89 JCR C version created. +* 02-27-90 GJF Fixed calling type, #include , fixed +* copyright. +* 08-14-90 SBM Removed now redundant #include +* 10-02-90 GJF New-style function declarator. +* 01-18-91 GJF ANSI naming. +* +*******************************************************************************/ + +#include +#include +#include + +/*** +*char *_strdup(string) - duplicate string into malloc'd memory +* +*Purpose: +* Allocates enough storage via malloc() for a copy of the +* string, copies the string into the new memory, and returns +* a pointer to it. +* +*Entry: +* char *string - string to copy into new memory +* +*Exit: +* returns a pointer to the newly allocated storage with the +* string in it. +* +* returns NULL if enough memory could not be allocated, or +* string was NULL. +* +*Uses: +* +*Exceptions: +* +*******************************************************************************/ + +char * _CALLTYPE1 _strdup ( + const char * string + ) +{ + char *memory; + + if (!string) + return(NULL); + + if (memory = malloc(strlen(string) + 1)) + return(strcpy(memory,string)); + + return(NULL); +} -- cgit v1.2.3