Changeset 1765 in MondoRescue for branches/2.2.5/mindi-busybox/libbb/llist.c


Ignore:
Timestamp:
Nov 4, 2007, 3:16:40 AM (17 years ago)
Author:
Bruno Cornec
Message:

Update to busybox 1.7.2

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.5/mindi-busybox/libbb/llist.c

    r821 r1765  
    88 * Copyright (C) 2006 Rob Landley <rob@landley.net>
    99 *
    10  * Licensed under the GPL v2, see the file LICENSE in this tarball.
     10 * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
    1111 */
    12 #include <stdlib.h>
     12
    1313#include "libbb.h"
    1414
    15 #ifdef L_llist_add_to
    1615/* Add data to the start of the linked list.  */
    1716void llist_add_to(llist_t **old_head, void *data)
    1817{
    1918    llist_t *new_head = xmalloc(sizeof(llist_t));
     19
    2020    new_head->data = data;
    2121    new_head->link = *old_head;
    2222    *old_head = new_head;
    2323}
    24 #endif
    2524
    26 #ifdef L_llist_add_to_end
    2725/* Add data to the end of the linked list.  */
    2826void llist_add_to_end(llist_t **list_head, void *data)
    2927{
    3028    llist_t *new_item = xmalloc(sizeof(llist_t));
     29
    3130    new_item->data = data;
    3231    new_item->link = NULL;
    3332
    34     if (!*list_head) *list_head = new_item;
     33    if (!*list_head)
     34        *list_head = new_item;
    3535    else {
    3636        llist_t *tail = *list_head;
    37         while (tail->link) tail = tail->link;
     37
     38        while (tail->link)
     39            tail = tail->link;
    3840        tail->link = new_item;
    3941    }
    4042}
    41 #endif
    4243
    43 #ifdef L_llist_pop
    4444/* Remove first element from the list and return it */
    4545void *llist_pop(llist_t **head)
    4646{
    47     void *data;
     47    void *data, *next;
    4848
    49     if(!*head) data = *head;
    50     else {
    51         void *next = (*head)->link;
    52         data = (*head)->data;
    53         free(*head);
    54         *head = next;
    55     }
     49    if (!*head)
     50        return NULL;
     51
     52    data = (*head)->data;
     53    next = (*head)->link;
     54    free(*head);
     55    *head = next;
    5656
    5757    return data;
    5858}
    59 #endif
    6059
    61 #ifdef L_llist_free
     60/* Unlink arbitrary given element from the list */
     61void llist_unlink(llist_t **head, llist_t *elm)
     62{
     63    llist_t *crt;
     64
     65    if (!(elm && *head))
     66        return;
     67
     68    if (elm == *head) {
     69        *head = (*head)->link;
     70        return;
     71    }
     72
     73    for (crt = *head; crt; crt = crt->link) {
     74        if (crt->link == elm) {
     75            crt->link = elm->link;
     76            return;
     77        }
     78    }
     79}
     80
    6281/* Recursively free all elements in the linked list.  If freeit != NULL
    6382 * call it on each datum in the list */
    64 void llist_free(llist_t *elm, void (*freeit)(void *data))
     83void llist_free(llist_t *elm, void (*freeit) (void *data))
    6584{
    6685    while (elm) {
    6786        void *data = llist_pop(&elm);
    68         if (freeit) freeit(data);
     87
     88        if (freeit)
     89            freeit(data);
    6990    }
    7091}
     92
     93#ifdef UNUSED
     94/* Reverse list order. */
     95llist_t *llist_rev(llist_t *list)
     96{
     97    llist_t *rev = NULL;
     98
     99    while (list) {
     100        llist_t *next = list->link;
     101
     102        list->link = rev;
     103        rev = list;
     104        list = next;
     105    }
     106    return rev;
     107}
    71108#endif
Note: See TracChangeset for help on using the changeset viewer.