#include <config.h>
#include <sys/types.h>
#include <stdio.h>
#ifdef STDC_HEADERS
# include <stdlib.h>
# include <stddef.h>
#else
# ifdef HAVE_STDLIB_H
# include <stdlib.h>
# endif
#endif
#include "sudo.h"
struct list_proto {
struct list_proto *prev;
struct list_proto *next;
};
struct list_head_proto {
struct list_proto *first;
struct list_proto *last;
};
void *
tq_pop(vh)
void *vh;
{
struct list_head_proto *h = (struct list_head_proto *)vh;
void *last = NULL;
if (!tq_empty(h)) {
last = (void *)h->last;
if (h->first == h->last) {
h->first = NULL;
h->last = NULL;
} else {
h->last = h->last->prev;
h->last->next = NULL;
}
}
return last;
}
void
list2tq(vh, vl)
void *vh;
void *vl;
{
struct list_head_proto *h = (struct list_head_proto *)vh;
struct list_proto *l = (struct list_proto *)vl;
if (l != NULL) {
#ifdef DEBUG
if (l->prev == NULL) {
warningx("list2tq called with non-semicircular list");
abort();
}
#endif
h->first = l;
h->last = l->prev;
l->prev = NULL;
} else {
h->first = NULL;
h->last = NULL;
}
}
void
list_append(vl1, vl2)
void *vl1;
void *vl2;
{
struct list_proto *l1 = (struct list_proto *)vl1;
struct list_proto *l2 = (struct list_proto *)vl2;
void *tail = l2->prev;
l1->prev->next = l2;
l2->prev = l1->prev;
l1->prev = tail;
}
void
tq_append(vh, vl)
void *vh;
void *vl;
{
struct list_head_proto *h = (struct list_head_proto *)vh;
struct list_proto *l = (struct list_proto *)vl;
void *tail = l->prev;
if (h->first == NULL)
h->first = l;
else
h->last->next = l;
l->prev = h->last;
h->last = tail;
}
void
tq_remove(vh, vl)
void *vh;
void *vl;
{
struct list_head_proto *h = (struct list_head_proto *)vh;
struct list_proto *l = (struct list_proto *)vl;
if (h->first == l && h->last == l) {
h->first = NULL;
h->last = NULL;
} else {
if (h->first == l) {
h->first = l->next;
h->first->prev = h->first;
} else if (h->last == l) {
h->last = l->prev;
h->last->next = NULL;
} else {
l->prev->next = l->next;
l->next->prev = l->prev;
}
}
}