mc/vfs/container.c

104 lines
2.3 KiB
C
Raw Normal View History

1998-02-27 07:54:42 +03:00
/* Virtual File System
Copyright (C) 1995 The Free Software Foundation
Written by: 1995 Ching Hui (mr854307@cs.nthu.edu.tw)
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License
as published by the Free Software Foundation; either version 2 of
the License, or (at your option) any later version.
1998-02-27 07:54:42 +03:00
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Library General Public License for more details.
1998-02-27 07:54:42 +03:00
You should have received a copy of the GNU Library General Public
License along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
1998-02-27 07:54:42 +03:00
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "utilvfs.h"
1998-10-24 00:18:48 +04:00
#include "xdirentry.h"
1998-02-27 07:54:42 +03:00
#include "container.h"
struct linklist *
linklist_init(void)
{
struct linklist *head;
head = g_new (struct linklist, 1);
1998-02-27 07:54:42 +03:00
if (head) {
head->prev = head->next = head;
head->data = NULL;
}
return head;
}
void
linklist_destroy(struct linklist *head, void (*destructor) (void *))
{
struct linklist *p, *q;
for (p = head->next; p != head; p = q) {
if (p->data && destructor)
(*destructor) (p->data);
q = p->next;
g_free(p);
1998-02-27 07:54:42 +03:00
}
g_free(head);
1998-02-27 07:54:42 +03:00
}
int
linklist_insert(struct linklist *head, void *data)
{
struct linklist *p;
p = g_new (struct linklist, 1);
1998-02-27 07:54:42 +03:00
if (p == NULL)
return 0;
p->data = data;
p->prev = head->prev;
p->next = head;
head->prev->next = p;
head->prev = p;
return 1;
}
void
linklist_delete_all(struct linklist *head, void (*destructor) (void *))
{
struct linklist *p, *q;
for (p = head->next; p != head; p = q) {
destructor(p->data);
q = p->next;
g_free(p);
1998-02-27 07:54:42 +03:00
}
head->next = head->prev = head;
head->data = NULL;
}
int
linklist_delete(struct linklist *head, void *data)
{
struct linklist *h = head->next;
while (h != head) {
if (h->data == data) {
h->prev->next = h->next;
h->next->prev = h->prev;
g_free(h);
1998-02-27 07:54:42 +03:00
return 1;
}
h = h->next;
}
return 0;
}