aboutsummaryrefslogtreecommitdiff
path: root/ares
diff options
context:
space:
mode:
authorYang Tse <yangsita@gmail.com>2008-09-15 15:28:26 +0000
committerYang Tse <yangsita@gmail.com>2008-09-15 15:28:26 +0000
commit8085c7a4500467df01d82b381e6830b2caf2dbbe (patch)
treef5a0f07505ba317ec9d197360ad5ca7eee0599b4 /ares
parent842de91168f86858415069192782212526cc9ebe (diff)
rearrange to allow internal/private use of ares_strcasecmp to any system that
lacks the strcasecmp function.
Diffstat (limited to 'ares')
-rw-r--r--ares/Makefile.inc4
-rw-r--r--ares/Makefile.vc63
-rw-r--r--ares/acountry.c15
-rw-r--r--ares/adig.c15
-rw-r--r--ares/ahost.c15
-rw-r--r--ares/ares_private.h10
-rw-r--r--ares/ares_strcasecmp.c67
-rw-r--r--ares/ares_strcasecmp.h31
-rw-r--r--ares/config-win32.h12
-rw-r--r--ares/setup.h13
-rw-r--r--ares/vc/areslib/areslib.dsp8
-rw-r--r--ares/windows_port.c21
12 files changed, 178 insertions, 36 deletions
diff --git a/ares/Makefile.inc b/ares/Makefile.inc
index 2a2c78420..1c22abb98 100644
--- a/ares/Makefile.inc
+++ b/ares/Makefile.inc
@@ -6,11 +6,11 @@ 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_strdup.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_llist.c ares__timeval.c
+ares_parse_ns_reply.c ares_llist.c ares__timeval.c ares_strcasecmp.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 \
- setup_once.h ares_llist.h ares_strdup.h
+ setup_once.h ares_llist.h ares_strdup.h ares_strcasecmp.h
MANPAGES= ares_destroy.3 ares_expand_name.3 ares_expand_string.3 ares_fds.3 \
ares_free_hostent.3 ares_free_string.3 ares_gethostbyaddr.3 \
diff --git a/ares/Makefile.vc6 b/ares/Makefile.vc6
index f02bd37e8..8bf5a08d2 100644
--- a/ares/Makefile.vc6
+++ b/ares/Makefile.vc6
@@ -57,6 +57,7 @@ OBJECTS = $(OBJ_DIR)\ares_fds.obj \
$(OBJ_DIR)\ares__read_line.obj \
$(OBJ_DIR)\ares_gethostbyname.obj \
$(OBJ_DIR)\ares_getnameinfo.obj \
+ $(OBJ_DIR)\ares_strcasecmp.obj \
$(OBJ_DIR)\ares_strerror.obj \
$(OBJ_DIR)\ares_cancel.obj \
$(OBJ_DIR)\ares_init.obj \
@@ -184,6 +185,8 @@ $(OBJ_DIR)\ares__read_line.obj: ares__read_line.c setup.h setup_once.h ares.h \
$(OBJ_DIR)\ares_gethostbyname.obj: ares_gethostbyname.c setup.h setup_once.h \
nameser.h ares.h ares_private.h ares_ipv6.h inet_net_pton.h bitncmp.h
+$(OBJ_DIR)\ares_strcasecmp.obj: ares_strcasecmp.c setup.h setup_once.h ares.h
+
$(OBJ_DIR)\ares_strerror.obj: ares_strerror.c setup.h setup_once.h ares.h
$(OBJ_DIR)\ares_cancel.obj: ares_cancel.c setup.h setup_once.h ares.h \
diff --git a/ares/acountry.c b/ares/acountry.c
index 169f81425..f74577f91 100644
--- a/ares/acountry.c
+++ b/ares/acountry.c
@@ -60,6 +60,21 @@
#include "inet_net_pton.h"
#include "inet_ntop.h"
+#ifndef HAVE_STRDUP
+# include "ares_strdup.h"
+# define strdup(ptr) ares_strdup(ptr)
+#endif
+
+#ifndef HAVE_STRCASECMP
+# include "ares_strcasecmp.h"
+# define strcasecmp(p1,p2) ares_strcasecmp(p1,p2)
+#endif
+
+#ifndef HAVE_STRNCASECMP
+# include "ares_strcasecmp.h"
+# define strncasecmp(p1,p2,n) ares_strncasecmp(p1,p2,n)
+#endif
+
#ifndef INADDR_NONE
#define INADDR_NONE 0xffffffff
#endif
diff --git a/ares/adig.c b/ares/adig.c
index 707fc8094..031ce8153 100644
--- a/ares/adig.c
+++ b/ares/adig.c
@@ -50,6 +50,21 @@
#include "inet_ntop.h"
#include "ares_getopt.h"
+#ifndef HAVE_STRDUP
+# include "ares_strdup.h"
+# define strdup(ptr) ares_strdup(ptr)
+#endif
+
+#ifndef HAVE_STRCASECMP
+# include "ares_strcasecmp.h"
+# define strcasecmp(p1,p2) ares_strcasecmp(p1,p2)
+#endif
+
+#ifndef HAVE_STRNCASECMP
+# include "ares_strcasecmp.h"
+# define strncasecmp(p1,p2,n) ares_strncasecmp(p1,p2,n)
+#endif
+
#ifdef WATT32
#undef WIN32 /* Redefined in MingW headers */
#endif
diff --git a/ares/ahost.c b/ares/ahost.c
index 882efcc77..567c7a024 100644
--- a/ares/ahost.c
+++ b/ares/ahost.c
@@ -43,6 +43,21 @@
#include "inet_net_pton.h"
#include "ares_getopt.h"
+#ifndef HAVE_STRDUP
+# include "ares_strdup.h"
+# define strdup(ptr) ares_strdup(ptr)
+#endif
+
+#ifndef HAVE_STRCASECMP
+# include "ares_strcasecmp.h"
+# define strcasecmp(p1,p2) ares_strcasecmp(p1,p2)
+#endif
+
+#ifndef HAVE_STRNCASECMP
+# include "ares_strcasecmp.h"
+# define strncasecmp(p1,p2,n) ares_strncasecmp(p1,p2,n)
+#endif
+
static void callback(void *arg, int status, int timeouts, struct hostent *host);
static void usage(void);
diff --git a/ares/ares_private.h b/ares/ares_private.h
index 877985bc9..e138cdd21 100644
--- a/ares/ares_private.h
+++ b/ares/ares_private.h
@@ -99,6 +99,16 @@
# define strdup(ptr) ares_strdup(ptr)
#endif
+#ifndef HAVE_STRCASECMP
+# include "ares_strcasecmp.h"
+# define strcasecmp(p1,p2) ares_strcasecmp(p1,p2)
+#endif
+
+#ifndef HAVE_STRNCASECMP
+# include "ares_strcasecmp.h"
+# define strncasecmp(p1,p2,n) ares_strncasecmp(p1,p2,n)
+#endif
+
struct query;
struct send_request {
diff --git a/ares/ares_strcasecmp.c b/ares/ares_strcasecmp.c
new file mode 100644
index 000000000..c3d1df9fc
--- /dev/null
+++ b/ares/ares_strcasecmp.c
@@ -0,0 +1,67 @@
+
+/* $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_strcasecmp.h"
+
+#ifndef HAVE_STRCASECMP
+int ares_strcasecmp(const char *a, const char *b)
+{
+#if defined(HAVE_STRCMPI)
+ return strcmpi(a, b);
+#elif defined(HAVE_STRICMP)
+ return stricmp(a, b);
+#else
+ size_t i;
+
+ for (i = 0; i < (size_t)-1; i++) {
+ int c1 = ISUPPER(a[i]) ? tolower(a[i]) : a[i];
+ int c2 = ISUPPER(b[i]) ? tolower(b[i]) : b[i];
+ if (c1 != c2)
+ return c1-c2;
+ if (!c1)
+ break;
+ }
+ return 0;
+#endif
+}
+#endif
+
+#ifndef HAVE_STRNCASECMP
+int ares_strncasecmp(const char *a, const char *b, size_t n)
+{
+#if defined(HAVE_STRNCMPI)
+ return strncmpi(a, b, n);
+#elif defined(HAVE_STRNICMP)
+ return strnicmp(a, b, n);
+#else
+ size_t i;
+
+ for (i = 0; i < n; i++) {
+ int c1 = ISUPPER(a[i]) ? tolower(a[i]) : a[i];
+ int c2 = ISUPPER(b[i]) ? tolower(b[i]) : b[i];
+ if (c1 != c2)
+ return c1-c2;
+ if (!c1)
+ break;
+ }
+ return 0;
+#endif
+}
+#endif
+
diff --git a/ares/ares_strcasecmp.h b/ares/ares_strcasecmp.h
new file mode 100644
index 000000000..85b053a9b
--- /dev/null
+++ b/ares/ares_strcasecmp.h
@@ -0,0 +1,31 @@
+#ifndef HEADER_CARES_STRCASECMP_H
+#define HEADER_CARES_STRCASECMP_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.
+ */
+
+#include "setup.h"
+
+#ifndef HAVE_STRCASECMP
+extern int ares_strcasecmp(const char *a, const char *b);
+#endif
+
+#ifndef HAVE_STRNCASECMP
+extern int ares_strncasecmp(const char *a, const char *b, size_t n);
+#endif
+
+#endif /* HEADER_CARES_STRCASECMP_H */
diff --git a/ares/config-win32.h b/ares/config-win32.h
index 5e26fa61d..6e548dcdf 100644
--- a/ares/config-win32.h
+++ b/ares/config-win32.h
@@ -79,9 +79,21 @@
/* Define if you have the ioctlsocket function. */
#define HAVE_IOCTLSOCKET 1
+/* Define if you have the strcasecmp function. */
+/* #define HAVE_STRCASECMP 1 */
+
/* Define if you have the strdup function. */
#define HAVE_STRDUP 1
+/* Define if you have the stricmp function. */
+#define HAVE_STRICMP 1
+
+/* Define if you have the strncasecmp function. */
+/* #define HAVE_STRNCASECMP 1 */
+
+/* Define if you have the strnicmp function. */
+#define HAVE_STRNICMP 1
+
/* Define if you have the recv function. */
#define HAVE_RECV 1
diff --git a/ares/setup.h b/ares/setup.h
index 5ae3b9e4e..5a8b2fa6a 100644
--- a/ares/setup.h
+++ b/ares/setup.h
@@ -139,19 +139,6 @@
#define HAVE_SYS_UIO_H
#endif
-#if (defined(WIN32) || defined(WATT32)) && \
- !(defined(__MINGW32__) || defined(NETWARE) || defined(__DJGPP__))
-/* protos for the functions we provide in windows_port.c */
-int ares_strncasecmp(const char *s1, const char *s2, int n);
-int ares_strcasecmp(const char *s1, const char *s2);
-
-/* use this define magic to prevent us from adding symbol names to the library
- that is a high-risk to collide with another libraries' attempts to do the
- same */
-#define strncasecmp(a,b,c) ares_strncasecmp(a,b,c)
-#define strcasecmp(a,b) ares_strcasecmp(a,b)
-#endif
-
/* IPv6 compatibility */
#if !defined(HAVE_AF_INET6)
#if defined(HAVE_PF_INET6)
diff --git a/ares/vc/areslib/areslib.dsp b/ares/vc/areslib/areslib.dsp
index 47805bd46..83cab07cb 100644
--- a/ares/vc/areslib/areslib.dsp
+++ b/ares/vc/areslib/areslib.dsp
@@ -181,6 +181,10 @@ SOURCE=..\..\ares_send.c
# End Source File
# Begin Source File
+SOURCE=..\..\ares_strcasecmp.c
+# End Source File
+# Begin Source File
+
SOURCE=..\..\ares_strerror.c
# End Source File
# Begin Source File
@@ -233,6 +237,10 @@ SOURCE=..\..\ares_private.h
# End Source File
# Begin Source File
+SOURCE=..\..\ares_strcasecmp.h
+# End Source File
+# Begin Source File
+
SOURCE=..\..\ares_version.h
# End Source File
# Begin Source File
diff --git a/ares/windows_port.c b/ares/windows_port.c
index 7ea6579fd..8b5e14977 100644
--- a/ares/windows_port.c
+++ b/ares/windows_port.c
@@ -34,27 +34,6 @@ WINAPI DllMain (HINSTANCE hnd, DWORD reason, LPVOID reserved)
}
#endif
-#ifndef __MINGW32__
-int
-ares_strncasecmp(const char *a, const char *b, int n)
-{
- int i;
-
- for (i = 0; i < n; i++) {
- int c1 = ISUPPER(a[i]) ? tolower(a[i]) : a[i];
- int c2 = ISUPPER(b[i]) ? tolower(b[i]) : b[i];
- if (c1 != c2) return c1-c2;
- }
- return 0;
-}
-
-int
-ares_strcasecmp(const char *a, const char *b)
-{
- return strncasecmp(a, b, strlen(a)+1);
-}
-#endif
-
int
ares_writev (ares_socket_t s, const struct iovec *vector, size_t count)
{