lsflib/src/list.c
author Markus Brökers <mbroeker@largo.homelinux.org>
Tue, 17 Aug 2010 18:57:57 +0200
changeset 139 cb1d3f4cf18e
parent 121 fef2ccfa7b12
permissions -rw-r--r--
execve returns a value on error and this catches it

/**
 * lsflib/src/list.c
 * Copyright (C) 2008 Markus Broeker
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <lsf/list.h>

Node *addnode (Node * node, char *data)
{
    Node *n;

    if ((n = malloc (sizeof (Node))) == NULL) {
        fprintf (stderr, "malloc fails: %s\n", data);
        return NULL;
    }

    if (!(n->data = strdup (data))) {
        fprintf (stderr, "strdup fails: %s\n", data);
        free (n);
        return NULL;
    }

    n->next = NULL;

    if (node != NULL) {
        node->next = n;
        node = n;
    } else
        node = n;

    return node;
}

Node *getnode (Node * aktuell)
{
    Node *begin;

    free (aktuell->data);
    begin = aktuell->next;
    free (aktuell);

    return begin;
}