...
Code Block | ||||
---|---|---|---|---|
| ||||
char *dupstring(const char *c_str) { size_t len; char *dup; len = strlen(c_str); dup = (char *)malloc(len + 1); assert(NULL != dup); memcpy(dup, c_str, len + 1); return dup; } |
...
Code Block | ||||
---|---|---|---|---|
| ||||
char *dupstring(const char *c_str) { size_t len; char *dup; len = strlen(c_str); dup = (char*)malloc(len + 1); /* detect and handle memory allocation error */ if (NULL == dup) { return NULL; } memcpy(dup, c_str, len + 1); return dup; } |
...