Merge pull request #6 from CindyLinz/master

my_strdup / my_strndup  malloc smaller
This commit is contained in:
Pedro 2014-05-17 15:06:44 +08:00
commit 6c0b3c3e90

View file

@ -188,7 +188,7 @@ char *strdup(const char *s) {
while( s[count] ) while( s[count] )
++count; ++count;
++count; ++count;
out = malloc(sizeof(char*) * count); out = malloc(sizeof(char) * count);
out[--count] = 0; out[--count] = 0;
while( --count >= 0 ) while( --count >= 0 )
out[count] = s[count]; out[count] = s[count];
@ -203,7 +203,7 @@ char *strndup(const char *s, int n) {
while( count < n && s[count] ) while( count < n && s[count] )
++count; ++count;
++count; ++count;
out = malloc(sizeof(char*) * count); out = malloc(sizeof(char) * count);
out[--count] = 0; out[--count] = 0;
while( --count >= 0 ) while( --count >= 0 )
out[count] = s[count]; out[count] = s[count];