Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

libfeos: tidy up strdup.c

  • Loading branch information...
commit 58a077a4e077cd51e4c4bf36ddbb530f455a44eb 1 parent a9e51b5
@fincs authored
Showing with 8 additions and 14 deletions.
  1. +8 −14 sdk/source/strdup.c
View
22 sdk/source/strdup.c
@@ -1,20 +1,14 @@
#include <stdlib.h>
#include <string.h>
-char* strdup(const char* str) {
- int size;
- char *rc;
+char* strdup(const char* str)
+{
+ if (!str) return NULL;
- if(str == NULL)
- return NULL;
+ int size = strlen(str) + 1;
+ char* newstr = (char*) malloc(size);
+ if (!newstr) return NULL;
- size = strlen(str)+1;
-
- rc = malloc(size);
- if(rc == NULL)
- return NULL;
-
- memcpy(rc, str, size);
- return rc;
+ memcpy(newstr, str, size);
+ return newstr;
}
-
Please sign in to comment.
Something went wrong with that request. Please try again.