2 /* Copyright 1998 by the Massachusetts Institute of Technology.
4 * Permission to use, copy, modify, and distribute this
5 * software and its documentation for any purpose and without
6 * fee is hereby granted, provided that the above copyright
7 * notice appear in all copies and that both that copyright
8 * notice and this permission notice appear in supporting
9 * documentation, and that the name of M.I.T. not be used in
10 * advertising or publicity pertaining to distribution of the
11 * software without specific, written prior permission.
12 * M.I.T. makes no representations about the suitability of
13 * this software for any purpose. It is provided "as is"
14 * without express or implied warranty.
17 #include "ares_setup.h"
20 #include "ares_private.h"
22 /* Routines for managing doubly-linked circular linked lists with a
26 /* Initialize a new head node */
27 void ares__init_list_head(struct list_node* head) {
33 /* Initialize a list node */
34 void ares__init_list_node(struct list_node* node, void* d) {
40 /* Returns true iff the given list is empty */
41 int ares__is_list_empty(struct list_node* head) {
42 return ((head->next == head) && (head->prev == head));
45 /* Inserts new_node before old_node */
46 void ares__insert_in_list(struct list_node* new_node,
47 struct list_node* old_node) {
48 new_node->next = old_node;
49 new_node->prev = old_node->prev;
50 old_node->prev->next = new_node;
51 old_node->prev = new_node;
54 /* Removes the node from the list it's in, if any */
55 void ares__remove_from_list(struct list_node* node) {
56 if (node->next != NULL) {
57 node->prev->next = node->next;
58 node->next->prev = node->prev;