* background.c (background_attention): Fix calling functions
[midnight-commander.git] / vfs / container.c
blob54ec169aec65fe253ddbb85e27064e25dbacb26b
1 /* Virtual File System
2 Copyright (C) 1995 The Free Software Foundation
4 Written by: 1995 Ching Hui (mr854307@cs.nthu.edu.tw)
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public License
8 as published by the Free Software Foundation; either version 2 of
9 the License, or (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Library General Public License for more details.
16 You should have received a copy of the GNU Library General Public
17 License along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
20 #include <config.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <unistd.h>
24 #include "utilvfs.h"
25 #include "xdirentry.h"
26 #include "container.h"
29 struct linklist *
30 linklist_init(void)
32 struct linklist *head;
34 head = g_new (struct linklist, 1);
35 if (head) {
36 head->prev = head->next = head;
37 head->data = NULL;
39 return head;
42 void
43 linklist_destroy(struct linklist *head, void (*destructor) (void *))
45 struct linklist *p, *q;
47 for (p = head->next; p != head; p = q) {
48 if (p->data && destructor)
49 (*destructor) (p->data);
50 q = p->next;
51 g_free(p);
53 g_free(head);
56 int
57 linklist_insert(struct linklist *head, void *data)
59 struct linklist *p;
61 p = g_new (struct linklist, 1);
62 if (p == NULL)
63 return 0;
64 p->data = data;
65 p->prev = head->prev;
66 p->next = head;
67 head->prev->next = p;
68 head->prev = p;
69 return 1;
72 void
73 linklist_delete_all(struct linklist *head, void (*destructor) (void *))
75 struct linklist *p, *q;
77 for (p = head->next; p != head; p = q) {
78 destructor(p->data);
79 q = p->next;
80 g_free(p);
82 head->next = head->prev = head;
83 head->data = NULL;
86 int
87 linklist_delete(struct linklist *head, void *data)
89 struct linklist *h = head->next;
91 while (h != head) {
92 if (h->data == data) {
93 h->prev->next = h->next;
94 h->next->prev = h->prev;
95 g_free(h);
96 return 1;
98 h = h->next;
100 return 0;