summaryrefslogtreecommitdiff
path: root/ares
diff options
context:
space:
mode:
authorYang Tse <yangsita@gmail.com>2007-10-02 02:18:01 +0000
committerYang Tse <yangsita@gmail.com>2007-10-02 02:18:01 +0000
commitb03abddb283fd0c04ce1d70de078175b0c32f563 (patch)
tree67f42e41935922a8b8c69e1e7eb5e8222b26937f /ares
parentccf083e26da3279c6528244d4bbc585304b551bc (diff)
downloadcurl-b03abddb283fd0c04ce1d70de078175b0c32f563.tar.gz
Avoid inline C99ism, and move c-ares routines for managing doubly-linked lists.
Diffstat (limited to 'ares')
-rw-r--r--ares/Makefile.inc2
-rw-r--r--ares/Makefile.vc64
-rw-r--r--ares/ares_llist.c87
-rw-r--r--ares/ares_llist.h43
-rw-r--r--ares/ares_private.h75
5 files changed, 136 insertions, 75 deletions
diff --git a/ares/Makefile.inc b/ares/Makefile.inc
index 8fad409c4..023ce7b6e 100644
--- a/ares/Makefile.inc
+++ b/ares/Makefile.inc
@@ -6,7 +6,7 @@ ares_timeout.c ares_destroy.c ares_mkquery.c ares_version.c \
ares_expand_name.c ares_parse_a_reply.c windows_port.c \
ares_expand_string.c ares_parse_ptr_reply.c ares_parse_aaaa_reply.c \
ares_getnameinfo.c inet_net_pton.c bitncmp.c inet_ntop.c \
-ares_parse_ns_reply.c
+ares_parse_ns_reply.c ares_llist.c
HHEADERS = ares.h ares_private.h setup.h ares_dns.h ares_version.h \
nameser.h inet_net_pton.h inet_ntop.h ares_ipv6.h bitncmp.h \
diff --git a/ares/Makefile.vc6 b/ares/Makefile.vc6
index 7982638aa..f1d7772d2 100644
--- a/ares/Makefile.vc6
+++ b/ares/Makefile.vc6
@@ -60,6 +60,7 @@ OBJECTS = $(OBJ_DIR)\ares_fds.obj \
$(OBJ_DIR)\ares_strerror.obj \
$(OBJ_DIR)\ares_cancel.obj \
$(OBJ_DIR)\ares_init.obj \
+ $(OBJ_DIR)\ares_llist.obj \
$(OBJ_DIR)\ares_timeout.obj \
$(OBJ_DIR)\ares_destroy.obj \
$(OBJ_DIR)\ares_mkquery.obj \
@@ -231,3 +232,6 @@ $(OBJ_DIR)\inet_ntop.obj: inet_ntop.c setup.h setup_once.h nameser.h \
ares_ipv6.h inet_ntop.h
$(OBJ_DIR)\ares_getopt.obj: ares_getopt.c ares_getopt.h
+
+$(OBJ_DIR)\ares_llist.obj: ares_llist.c setup.h setup_once.h ares.h \
+ ares_private.h ares_llist.h
diff --git a/ares/ares_llist.c b/ares/ares_llist.c
new file mode 100644
index 000000000..77cbd4d07
--- /dev/null
+++ b/ares/ares_llist.c
@@ -0,0 +1,87 @@
+/* $Id$ */
+
+/* Copyright 1998 by the Massachusetts Institute of Technology.
+ *
+ * Permission to use, copy, modify, and distribute this
+ * software and its documentation for any purpose and without
+ * fee is hereby granted, provided that the above copyright
+ * notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting
+ * documentation, and that the name of M.I.T. not be used in
+ * advertising or publicity pertaining to distribution of the
+ * software without specific, written prior permission.
+ * M.I.T. makes no representations about the suitability of
+ * this software for any purpose. It is provided "as is"
+ * without express or implied warranty.
+ */
+
+#include "setup.h"
+
+#include "ares.h"
+#include "ares_private.h"
+
+/* Routines for managing doubly-linked circular linked lists with a
+ * dummy head.
+ */
+
+/* Initialize a new head node */
+void ares__init_list_head(struct list_node* head) {
+ head->prev = head;
+ head->next = head;
+ head->data = NULL;
+}
+
+/* Initialize a list node */
+void ares__init_list_node(struct list_node* node, void* d) {
+ node->prev = NULL;
+ node->next = NULL;
+ node->data = d;
+}
+
+/* Returns true iff the given list is empty */
+int ares__is_list_empty(struct list_node* head) {
+ return ((head->next == head) && (head->prev == head));
+}
+
+/* Inserts new_node before old_node */
+void ares__insert_in_list(struct list_node* new_node,
+ struct list_node* old_node) {
+ new_node->next = old_node;
+ new_node->prev = old_node->prev;
+ old_node->prev->next = new_node;
+ old_node->prev = new_node;
+}
+
+/* Removes the node from the list it's in, if any */
+void ares__remove_from_list(struct list_node* node) {
+ if (node->next != NULL) {
+ node->prev->next = node->next;
+ node->next->prev = node->prev;
+ node->prev = NULL;
+ node->next = NULL;
+ }
+}
+
+/* Swap the contents of two lists */
+void ares__swap_lists(struct list_node* head_a,
+ struct list_node* head_b) {
+ int is_a_empty = ares__is_list_empty(head_a);
+ int is_b_empty = ares__is_list_empty(head_b);
+ struct list_node old_a = *head_a;
+ struct list_node old_b = *head_b;
+
+ if (is_a_empty) {
+ ares__init_list_head(head_b);
+ } else {
+ *head_b = old_a;
+ old_a.next->prev = head_b;
+ old_a.prev->next = head_b;
+ }
+ if (is_b_empty) {
+ ares__init_list_head(head_a);
+ } else {
+ *head_a = old_b;
+ old_b.next->prev = head_a;
+ old_b.prev->next = head_a;
+ }
+}
diff --git a/ares/ares_llist.h b/ares/ares_llist.h
new file mode 100644
index 000000000..d20af7e15
--- /dev/null
+++ b/ares/ares_llist.h
@@ -0,0 +1,43 @@
+#ifndef __ARES_LLIST_H
+#define __ARES_LLIST_H
+
+/* $Id$ */
+
+/* Copyright 1998 by the Massachusetts Institute of Technology.
+ *
+ * Permission to use, copy, modify, and distribute this
+ * software and its documentation for any purpose and without
+ * fee is hereby granted, provided that the above copyright
+ * notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting
+ * documentation, and that the name of M.I.T. not be used in
+ * advertising or publicity pertaining to distribution of the
+ * software without specific, written prior permission.
+ * M.I.T. makes no representations about the suitability of
+ * this software for any purpose. It is provided "as is"
+ * without express or implied warranty.
+ */
+
+
+/* Node definition for circular, doubly-linked list */
+struct list_node {
+ struct list_node *prev;
+ struct list_node *next;
+ void* data;
+};
+
+void ares__init_list_head(struct list_node* head);
+
+void ares__init_list_node(struct list_node* node, void* d);
+
+int ares__is_list_empty(struct list_node* head);
+
+void ares__insert_in_list(struct list_node* new_node,
+ struct list_node* old_node);
+
+void ares__remove_from_list(struct list_node* node);
+
+void ares__swap_lists(struct list_node* head_a,
+ struct list_node* head_b);
+
+#endif /* __ARES_LLIST_H */
diff --git a/ares/ares_private.h b/ares/ares_private.h
index 34e4692c4..26f55db5a 100644
--- a/ares/ares_private.h
+++ b/ares/ares_private.h
@@ -83,16 +83,10 @@
#define ARES_ID_KEY_LEN 31
#include "ares_ipv6.h"
+#include "ares_llist.h"
struct query;
-/* Node definition for circular, doubly-linked list */
-struct list_node {
- struct list_node *prev;
- struct list_node *next;
- void* data;
-};
-
struct send_request {
/* Remaining data to send */
const unsigned char *data;
@@ -265,73 +259,6 @@ int ares__read_line(FILE *fp, char **buf, int *bufsize);
void ares__free_query(struct query *query);
short ares__generate_new_id(rc4_key* key);
-
-/* Routines for managing doubly-linked circular linked lists with a
- * dummy head.
- */
-
-/* Initialize a new head node */
-static inline void ares__init_list_head(struct list_node* head) {
- head->prev = head;
- head->next = head;
- head->data = NULL;
-}
-
-/* Initialize a list node */
-static inline void ares__init_list_node(struct list_node* node, void* d) {
- node->prev = NULL;
- node->next = NULL;
- node->data = d;
-}
-
-/* Returns true iff the given list is empty */
-static inline int ares__is_list_empty(struct list_node* head) {
- return ((head->next == head) && (head->prev == head));
-}
-
-/* Inserts new_node before old_node */
-static inline void ares__insert_in_list(struct list_node* new_node,
- struct list_node* old_node) {
- new_node->next = old_node;
- new_node->prev = old_node->prev;
- old_node->prev->next = new_node;
- old_node->prev = new_node;
-}
-
-/* Removes the node from the list it's in, if any */
-static inline void ares__remove_from_list(struct list_node* node) {
- if (node->next != NULL) {
- node->prev->next = node->next;
- node->next->prev = node->prev;
- node->prev = NULL;
- node->next = NULL;
- }
-}
-
-/* Swap the contents of two lists */
-static inline void ares__swap_lists(struct list_node* head_a,
- struct list_node* head_b) {
- int is_a_empty = ares__is_list_empty(head_a);
- int is_b_empty = ares__is_list_empty(head_b);
- struct list_node old_a = *head_a;
- struct list_node old_b = *head_b;
-
- if (is_a_empty) {
- ares__init_list_head(head_b);
- } else {
- *head_b = old_a;
- old_a.next->prev = head_b;
- old_a.prev->next = head_b;
- }
- if (is_b_empty) {
- ares__init_list_head(head_a);
- } else {
- *head_a = old_b;
- old_b.next->prev = head_a;
- old_b.prev->next = head_a;
- }
-}
-
#define ARES_SWAP_BYTE(a,b) \
{ unsigned char swapByte = *(a); *(a) = *(b); *(b) = swapByte; }