]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
Avoid inline C99ism, and move c-ares routines for managing doubly-linked lists.
authorYang Tse <yangsita@gmail.com>
Tue, 2 Oct 2007 02:18:01 +0000 (02:18 +0000)
committerYang Tse <yangsita@gmail.com>
Tue, 2 Oct 2007 02:18:01 +0000 (02:18 +0000)
ares/Makefile.inc
ares/Makefile.vc6
ares/ares_llist.c [new file with mode: 0644]
ares/ares_llist.h [new file with mode: 0644]
ares/ares_private.h

index 8fad409c4089877fa78302254a954738b84d9ad0..023ce7b6e6a029207f4d3883a6ff892eb767ddcf 100644 (file)
@@ -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      \
index 7982638aa44875c06aebb7ce93d9efc71941c482..f1d7772d2d69ef13c7029290ad7afd8cbe6676aa 100644 (file)
@@ -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 (file)
index 0000000..77cbd4d
--- /dev/null
@@ -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 (file)
index 0000000..d20af7e
--- /dev/null
@@ -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 */
index 34e4692c41a18c4771943888c70da2aa2c9d4559..26f55db5a64e90420417408e215bf2164d31f1a8 100644 (file)
 #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; }