|
| iMatix home page | << | < | > | >> |
SFLVersion 2.11 |
#include "sflmem.h"
char *
mem_strdup_ (
MEMTRN *trn, /* Associated transaction */
const char *string, /* String to copy */
const char *filename, /* Name of source file making call */
size_t lineno /* Line number in calling source */
)
Saves a string in dynamic memory. Use the mem_strdup macro to call this function! The caller is responsible for freeing the space allocated 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.
{
char *copy;
size_t str_len;
if (string) /* If string not null, copy it */
{
str_len = strlen (string) + 1;
copy = mem alloc (trn, str_len, filename, lineno);
if (copy)
strncpy (copy, string, str_len);
}
else
copy = NULL; /* Just pass-through a NULL */
return (copy);
}
| | << | < | > | >> |
|