rearrange to allow internal/private use of ares_strcasecmp to any system that

lacks the strcasecmp function.
This commit is contained in:
Yang Tse 2008-09-15 15:28:26 +00:00
parent 842de91168
commit 8085c7a450
12 changed files with 178 additions and 36 deletions

View File

@ -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 \

View File

@ -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 \

View File

@ -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

View File

@ -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

View File

@ -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);

View File

@ -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 {

67
ares/ares_strcasecmp.c Normal file
View File

@ -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

31
ares/ares_strcasecmp.h Normal file
View File

@ -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 */

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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)
{