| iMatix home page
| << | < | > | >>
SFL Logo SFL
Version 2.11

 

strdupl

#include "sflstr.h"
char *
strdupl (
    const char *string)

Synopsis

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.

Source Code - (sflstr.c)

{
    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);
}

| << | < | > | >> iMatix Copyright © 1996-2000 iMatix Corporation