| iMatix home page | << | < | > | >> |
![]() Version 2.11 |
#include "sflstr.h" char * strdupl ( const char *string)
Makes a duplicate of string, obtaining space with a call to malloc(). The allocated space is strlen (string) + 1 bytes long. The caller is responsible for freeing the space allocated by strdup when it is no longer needed. Returns a pointer to the allocated string, which holds a copy of the parameter string. Returns NULL if there was insufficient heap storage available to allocate the string, or if the original string was itself NULL. Use this function in place of the non-portable strdup() function. You may also want to use the more robust mem strdup () function.
{ char *copy; size_t length; if (string) { length = strlen (string) + 1; copy = malloc (length); if (copy) strncpy (copy, string, length); } else copy = NULL; return (copy); }
| << | < | > | >> |
![]() |