src/adlist.c
list *listDup(list *orig)
{
    list *copy;
    listIter iter;
    listNode *node;

    if ((copy = listCreate()) == NULL)
        return NULL;
    copy->dup = orig->dup;
    copy->free = orig->free;
    copy->match = orig->match;
    listRewind(orig, &iter);
    while((node = listNext(&iter)) != NULL) {
        void *value;

        if (copy->dup) {
            value = copy->dup(node->value);
            if (value == NULL) {
                listRelease(copy);
                return NULL;
            }
        } else
            value = node->value;
        if (listAddNodeTail(copy, value) == NULL) {
            listRelease(copy);
            return NULL;
        }
    }
    return copy;
}
/* Duplicate the whole list. On out of memory NULL is returned.
 * On success a copy of the original list is returned.
 *
 * The 'Dup' method set with listSetDupMethod() function is used
 * to copy the node value. Otherwise the same pointer value of
 * the original node is used as value of the copied node.
 *
 * The original list both on success or error is never modified. */
Duplicate the whole list. On out of memory NULL is returned.
On success a copy of the original list is returned.

The 'Dup' method set with listSetDupMethod() function is used
to copy the node value. Otherwise the same pointer value of
the original node is used as value of the copied node.

The original list both on success or error is never modified.
Duplicate the whole list . On out of memory NULL is returned . On success a copy of the original list is returned . The ' Dup ' method set with listSetDupMethod () function is used to copy the node value . Otherwise the same pointer value of the original node is used as value of the copied node . The original list both on success or error is never modified .
list *listDup(list *orig)
{
    list *copy;
    listIter iter;
    listNode *node;
    if ((copy = listCreate()) == NULL)
        return NULL;
    copy->dup = orig->dup;
    copy->free = orig->free;
    copy->match = orig->match;
    listRewind(orig, &iter);
    while((node = listNext(&iter)) != NULL) {
        void *value;
        if (copy->dup) {
            value = copy->dup(node->value);
            if (value == NULL) {
                listRelease(copy);
                return NULL;
            }
        } else
            value = node->value;
        if (listAddNodeTail(copy, value) == NULL) {
            listRelease(copy);
            return NULL;
        }
    }
    return copy;
}
list * listDup ( list * orig ) { list * copy ; listIter iter ; listNode * node ; if ( ( copy = listCreate ( ) ) == NULL ) return NULL ; copy -> dup = orig -> dup ; copy -> free = orig -> free ; copy -> match = orig -> match ; listRewind ( orig , & iter ) ; while ( ( node = listNext ( & iter ) ) != NULL ) { void * value ; if ( copy -> dup ) { value = copy -> dup ( node -> value ) ; if ( value == NULL ) { listRelease ( copy ) ; return NULL ; } } else value = node -> value ; if ( listAddNodeTail ( copy , value ) == NULL ) { listRelease ( copy ) ; return NULL ; } } return copy ; }
Duplicate the whole list.
Duplicate the whole list .