lsflib/src/list.c
author Markus Bröker <mbroeker@largo.dyndns.tv>
Thu, 16 Apr 2009 12:50:39 +0200
changeset 71 9ac5a589211e
parent 9 c3fecc82ade6
child 77 49e0babccb23
permissions -rw-r--r--
Makefile: Little Improvements * not all platforms have gnu find * not all platforms have rm The user may adjust the settings in the header of the makefile committer: Markus Bröker <mbroeker@largo.homelinux.org>

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

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

#include <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;
}