src/slist/slist.c
/*
 * Returns 0 if successful or -1 in case of an error.
 * (in case of an error the list is unchanged)
 */
Returns 0 if successful or -1 in case of an error.
(in case of an error the list is unchanged)
Returns 0 if successful or - 1 in case of an error . ( in case of an error the list is unchanged )
int slist_append_safe(slist_t ** slist, void * data)
{
    if ((*slist)->len == (*slist)->size)
    {
        slist_t * tmp;
        size_t sz = (*slist)->size;
        (*slist)->size = (sz >= SLIST_DEFAULT_SIZE) ?
                (sz <= SLIST_MAX_SZ) ?
                        sz * 2 : sz + SLIST_MAX_SZ : SLIST_DEFAULT_SIZE;
        tmp = (slist_t *) realloc(
                *slist,
                sizeof(slist_t) + sizeof(void *) * (*slist)->size);
        if (tmp == NULL)
        {
            (*slist)->size = sz;
            return -1;
        }
        *slist = tmp;
    }
    slist_append((*slist), data);
    return 0;
}
int slist_append_safe ( slist_t * * slist , void * data ) { if ( ( * slist ) -> len == ( * slist ) -> size ) { slist_t * tmp ; size_t sz = ( * slist ) -> size ; ( * slist ) -> size = ( sz >= SLIST_DEFAULT_SIZE ) ? ( sz <= SLIST_MAX_SZ ) ? sz * 2 : sz + SLIST_MAX_SZ : SLIST_DEFAULT_SIZE ; tmp = ( slist_t * ) realloc ( * slist , sizeof ( slist_t ) + sizeof ( void * ) * ( * slist ) -> size ) ; if ( tmp == NULL ) { ( * slist ) -> size = sz ; return -1 ; } * slist = tmp ; } slist_append ( ( * slist ) , data ) ; return 0 ; }
Returns 0 if successful or -1 in case of an error.
Returns 0 if successful or - 1 in case of an error .
/* double the size when > 0 and <  SLIST_MAX_SZ */ /* an error has occurred */ /* overwrite the original value with the new one */