Portability updates for legacy systems. (#92)

Socklen_t should not be used in code, instead ares_socklen_t should be used.
Convert ssize_t to ares_ssize_t for portability since the public API now exposes this.
pull/95/head
Brad House 8 years ago committed by GitHub
parent 6b452db894
commit 919dc45f2f
  1. 14
      CMakeLists.txt
  2. 6
      ares.h
  3. 2
      ares_build.h.cmake
  4. 13
      ares_build.h.dist
  5. 6
      ares_build.h.in
  6. 10
      ares_config.h.cmake
  7. 2
      ares_expand_name.c
  8. 2
      ares_expand_string.c
  9. 4
      ares_init.c
  10. 12
      ares_nowarn.c
  11. 4
      ares_nowarn.h
  12. 24
      ares_process.c
  13. 12
      ares_set_socket_functions.3
  14. 4
      ares_writev.c
  15. 2
      ares_writev.h
  16. 5
      config-dos.h
  17. 14
      config-win32.h
  18. 8
      configure.ac
  19. 4
      inet_net_pton.c
  20. 10
      setup_once.h

@ -407,6 +407,20 @@ ELSE ()
Set (CARES_TYPEOF_ARES_SOCKLEN_T "int")
ENDIF ()
IF (HAVE_SSIZE_T)
Set (CARES_TYPEOF_ARES_SSIZE_T "ssize_t")
ELSE ()
IF (WIN32)
IF ("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
Set (CARES_TYPEOF_ARES_SSIZE_T "__int64")
ELSE ()
Set (CARES_TYPEOF_ARES_SSIZE_T "int")
ENDIF ()
ELSE ()
Set (CARES_TYPEOF_ARES_SSIZE_T "long")
ENDIF ()
ENDIF ()
IF (HAVE_FCNTL AND HAVE_O_NONBLOCK)
SET (HAVE_FCNTL_O_NONBLOCK 1)
ENDIF ()

@ -368,9 +368,9 @@ struct iovec;
struct ares_socket_functions {
ares_socket_t(*asocket)(int, int, int, void *);
int(*aclose)(ares_socket_t, void *);
int(*aconnect)(ares_socket_t, const struct sockaddr *, socklen_t, void *);
ssize_t(*arecvfrom)(ares_socket_t, void *, size_t, int, struct sockaddr *, socklen_t *, void *);
ssize_t(*asendv)(ares_socket_t, const struct iovec *, int, void *);
int(*aconnect)(ares_socket_t, const struct sockaddr *, ares_socklen_t, void *);
ares_ssize_t(*arecvfrom)(ares_socket_t, void *, size_t, int, struct sockaddr *, ares_socklen_t *, void *);
ares_ssize_t(*asendv)(ares_socket_t, const struct iovec *, int, void *);
};
CARES_EXTERN void ares_set_socket_functions(ares_channel channel,

@ -2,6 +2,7 @@
#define __CARES_BUILD_H
#define CARES_TYPEOF_ARES_SOCKLEN_T @CARES_TYPEOF_ARES_SOCKLEN_T@
#define CARES_TYPEOF_ARES_SSIZE_T @CARES_TYPEOF_ARES_SSIZE_T@
/* Prefix names with CARES_ to make sure they don't conflict with other config.h
* files. We need to include some dependent headers that may be system specific
@ -35,5 +36,6 @@
typedef CARES_TYPEOF_ARES_SOCKLEN_T ares_socklen_t;
typedef CARES_TYPEOF_ARES_SSIZE_T ares_ssize_t;
#endif /* __CARES_BUILD_H */

@ -191,4 +191,17 @@
typedef CARES_TYPEOF_ARES_SOCKLEN_T ares_socklen_t;
#endif
/* Data type definition of ares_ssize_t. */
#ifdef _WIN32
# ifdef _WIN64
# define CARES_TYPEOF_ARES_SSIZE_T __int64
# else
# define CARES_TYPEOF_ARES_SSIZE_T long
# endif
#else
# define CARES_TYPEOF_ARES_SSIZE_T ssize_t;
#endif
typedef CARES_TYPEOF_ARES_SSIZE_T ares_ssize_t;
#endif /* __CARES_BUILD_H */

@ -91,4 +91,10 @@
/* Data type definition of ares_socklen_t. */
typedef CARES_TYPEOF_ARES_SOCKLEN_T ares_socklen_t;
/* Integral data type used for ares_ssize_t. */
#undef CARES_TYPEOF_ARES_SSIZE_T
/* Data type definition of ares_ssize_t. */
typedef CARES_TYPEOF_ARES_SSIZE_T ares_ssize_t;
#endif /* __CARES_BUILD_H */

@ -421,13 +421,3 @@
/* Type to use in place of in_addr_t when system does not provide it. */
#undef in_addr_t
#cmakedefine HAVE_SSIZE_T
/* Create our own ssize_t */
#ifndef HAVE_SSIZE_T
# ifdef _WIN64
typedef __int64 ssize_t;
# else
typedef long ssize_t;
# endif
#endif

@ -66,7 +66,7 @@ int ares_expand_name(const unsigned char *encoded, const unsigned char *abuf,
char *q;
const unsigned char *p;
union {
ssize_t sig;
ares_ssize_t sig;
size_t uns;
} nlen;

@ -41,7 +41,7 @@ int ares_expand_string(const unsigned char *encoded,
{
unsigned char *q;
union {
ssize_t sig;
ares_ssize_t sig;
size_t uns;
} elen;

@ -84,7 +84,7 @@ static int config_sortlist(struct apattern **sortlist, int *nsort,
const char *str);
static int sortlist_alloc(struct apattern **sortlist, int *nsort,
struct apattern *pat);
static int ip_addr(const char *s, ssize_t len, struct in_addr *addr);
static int ip_addr(const char *s, ares_ssize_t len, struct in_addr *addr);
static void natural_mask(struct apattern *pat);
#if !defined(WIN32) && !defined(WATT32) && \
!defined(ANDROID) && !defined(__ANDROID__) && !defined(CARES_USE_LIBRESOLV)
@ -2163,7 +2163,7 @@ static char *try_config(char *s, const char *opt, char scc)
}
#endif /* !WIN32 & !WATT32 & !ANDROID & !__ANDROID__ */
static int ip_addr(const char *ipbuf, ssize_t len, struct in_addr *addr)
static int ip_addr(const char *ipbuf, ares_ssize_t len, struct in_addr *addr)
{
/* Four octets and three periods yields at most 15 characters. */

@ -151,10 +151,10 @@ int aresx_sltosi(long slnum)
}
/*
** signed ssize_t to signed int
** signed ares_ssize_t to signed int
*/
int aresx_sztosi(ssize_t sznum)
int aresx_sztosi(ares_ssize_t sznum)
{
#ifdef __INTEL_COMPILER
# pragma warning(push)
@ -162,7 +162,7 @@ int aresx_sztosi(ssize_t sznum)
#endif
DEBUGASSERT(sznum >= 0);
return (int)(sznum & (ssize_t) CARES_MASK_SINT);
return (int)(sznum & (ares_ssize_t) CARES_MASK_SINT);
#ifdef __INTEL_COMPILER
# pragma warning(pop)
@ -170,10 +170,10 @@ int aresx_sztosi(ssize_t sznum)
}
/*
** signed ssize_t to unsigned int
** signed ares_ssize_t to unsigned int
*/
unsigned int aresx_sztoui(ssize_t sznum)
unsigned int aresx_sztoui(ares_ssize_t sznum)
{
#ifdef __INTEL_COMPILER
# pragma warning(push)
@ -181,7 +181,7 @@ unsigned int aresx_sztoui(ssize_t sznum)
#endif
DEBUGASSERT(sznum >= 0);
return (unsigned int)(sznum & (ssize_t) CARES_MASK_UINT);
return (unsigned int)(sznum & (ares_ssize_t) CARES_MASK_UINT);
#ifdef __INTEL_COMPILER
# pragma warning(pop)

@ -25,9 +25,9 @@ short aresx_sitoss(int sinum);
int aresx_sltosi(long slnum);
int aresx_sztosi(ssize_t sznum);
int aresx_sztosi(ares_ssize_t sznum);
unsigned int aresx_sztoui(ssize_t sznum);
unsigned int aresx_sztoui(ares_ssize_t sznum);
unsigned short aresx_sitous(int sinum);

@ -65,7 +65,7 @@ static void read_tcp_data(ares_channel channel, fd_set *read_fds,
static void read_udp_packets(ares_channel channel, fd_set *read_fds,
ares_socket_t read_fd, struct timeval *now);
static void advance_tcp_send_queue(ares_channel channel, int whichserver,
ssize_t num_bytes);
ares_ssize_t num_bytes);
static void process_timeouts(ares_channel channel, struct timeval *now);
static void process_broken_connections(ares_channel channel,
struct timeval *now);
@ -175,7 +175,7 @@ static int try_again(int errnum)
return 0;
}
static ssize_t socket_writev(ares_channel channel, ares_socket_t s, const struct iovec * vec, int len)
static ares_ssize_t socket_writev(ares_channel channel, ares_socket_t s, const struct iovec * vec, int len)
{
if (channel->sock_funcs)
return channel->sock_funcs->asendv(s, vec, len, channel->sock_func_cb_data);
@ -183,7 +183,7 @@ static ssize_t socket_writev(ares_channel channel, ares_socket_t s, const struct
return writev(s, vec, len);
}
static ssize_t socket_write(ares_channel channel, ares_socket_t s, const void * data, size_t len)
static ares_ssize_t socket_write(ares_channel channel, ares_socket_t s, const void * data, size_t len)
{
if (channel->sock_funcs)
{
@ -207,8 +207,8 @@ static void write_tcp_data(ares_channel channel,
struct send_request *sendreq;
struct iovec *vec;
int i;
ssize_t scount;
ssize_t wcount;
ares_ssize_t scount;
ares_ssize_t wcount;
size_t n;
if(!write_fds && (write_fd == ARES_SOCKET_BAD))
@ -291,7 +291,7 @@ static void write_tcp_data(ares_channel channel,
/* Consume the given number of bytes from the head of the TCP send queue. */
static void advance_tcp_send_queue(ares_channel channel, int whichserver,
ssize_t num_bytes)
ares_ssize_t num_bytes)
{
struct send_request *sendreq;
struct server_state *server = &channel->servers[whichserver];
@ -319,13 +319,13 @@ static void advance_tcp_send_queue(ares_channel channel, int whichserver,
}
}
static ssize_t socket_recvfrom(ares_channel channel,
static ares_ssize_t socket_recvfrom(ares_channel channel,
ares_socket_t s,
void * data,
size_t data_len,
int flags,
struct sockaddr *from,
socklen_t *from_len)
ares_socklen_t *from_len)
{
if (channel->sock_funcs)
return channel->sock_funcs->arecvfrom(s, data, data_len,
@ -339,7 +339,7 @@ static ssize_t socket_recvfrom(ares_channel channel,
#endif
}
static ssize_t socket_recv(ares_channel channel,
static ares_ssize_t socket_recv(ares_channel channel,
ares_socket_t s,
void * data,
size_t data_len)
@ -360,7 +360,7 @@ static void read_tcp_data(ares_channel channel, fd_set *read_fds,
{
struct server_state *server;
int i;
ssize_t count;
ares_ssize_t count;
if(!read_fds && (read_fd == ARES_SOCKET_BAD))
/* no possible action */
@ -458,7 +458,7 @@ static void read_udp_packets(ares_channel channel, fd_set *read_fds,
{
struct server_state *server;
int i;
ssize_t count;
ares_ssize_t count;
unsigned char buf[MAXENDSSZ + 1];
#ifdef HAVE_RECVFROM
ares_socklen_t fromlen;
@ -1024,7 +1024,7 @@ static ares_socket_t open_socket(ares_channel channel, int af, int type, int pro
static int connect_socket(ares_channel channel, ares_socket_t sockfd,
const struct sockaddr * addr,
socklen_t addrlen)
ares_socklen_t addrlen)
{
if (channel->sock_funcs != 0)
return channel->sock_funcs->aconnect(sockfd,

@ -9,9 +9,9 @@ ares_set_socket_functions \- Set socket io callbacks
.B struct ares_socket_functions {
ares_socket_t(*\fIasocket\fP)(int, int, int, void *);
int(*\fIaclose\fP)(ares_socket_t, void *);
int(*\fIaconnect\fP)(ares_socket_t, const struct sockaddr *, socklen_t, void *);
ssize_t(*\fIarecvfrom\fP)(ares_socket_t, void *, size_t, int, struct sockaddr *, socklen_t *, void *);
ssize_t(*\fIasendv\fP)(ares_socket_t, const struct iovec *, int, void *);
int(*\fIaconnect\fP)(ares_socket_t, const struct sockaddr *, ares_socklen_t, void *);
ares_ssize_t(*\fIarecvfrom\fP)(ares_socket_t, void *, size_t, int, struct sockaddr *, ares_socklen_t *, void *);
ares_ssize_t(*\fIasendv\fP)(ares_socket_t, const struct iovec *, int, void *);
};
.PP
@ -60,21 +60,21 @@ Closes the socket endpoint indicated by \fIfd\fP. See
.BR close(2)
.TP 18
.B \fIaconnect\fP
.B int(*)(ares_socket_t \fIfd\fP, const struct sockaddr * \fIaddr\fP, socklen_t \fIaddr_len\fP, void * \fIuser_data\fP)
.B int(*)(ares_socket_t \fIfd\fP, const struct sockaddr * \fIaddr\fP, ares_socklen_t \fIaddr_len\fP, void * \fIuser_data\fP)
.br
Initiate a connection to the address indicated by \fIaddr\fP on a socket. See
.BR connect(2)
.TP 18
.B \fIarecvfrom\fP
.B ssize_t(*)(ares_socket_t \fIfd\fP, void * \fIbuffer\fP, size_t \fIbuf_size\fP, int \fIflags\fP, struct sockaddr * \fIaddr\fP, socklen_t * \fIaddr_len\fP, void * \fIuser_data\fP)
.B ares_ssize_t(*)(ares_socket_t \fIfd\fP, void * \fIbuffer\fP, size_t \fIbuf_size\fP, int \fIflags\fP, struct sockaddr * \fIaddr\fP, ares_socklen_t * \fIaddr_len\fP, void * \fIuser_data\fP)
.br
Receives data from remote socket endpoint, if available. If the \fIaddr\fP parameter is not NULL and the connection protocol provides the source address, the callback should fill this in. See
.BR recvfrom(2)
.TP 18
.B \fIasendv\fP
.B ssize_t(*)(ares_socket_t \fIfd\fP, const struct iovec * \fIdata\fP, int \fIlen\fP, void * \fIuser_data\fP)
.B ares_ssize_t(*)(ares_socket_t \fIfd\fP, const struct iovec * \fIdata\fP, int \fIlen\fP, void * \fIuser_data\fP)
.br
Send data, as provided by the iovec array \fIdata\fP, to the socket endpoint. See
.BR writev(2),

@ -25,12 +25,12 @@
#include "ares_private.h"
#ifndef HAVE_WRITEV
ssize_t ares_writev(ares_socket_t s, const struct iovec *iov, int iovcnt)
ares_ssize_t ares_writev(ares_socket_t s, const struct iovec *iov, int iovcnt)
{
char *buffer, *bp;
int i;
size_t bytes = 0;
ssize_t result;
ares_ssize_t result;
/* Validate iovcnt */
if (iovcnt <= 0)

@ -29,7 +29,7 @@ struct iovec
size_t iov_len; /* Length of data. */
};
extern ssize_t ares_writev(ares_socket_t s, const struct iovec *iov, int iovcnt);
extern ares_ssize_t ares_writev(ares_socket_t s, const struct iovec *iov, int iovcnt);
#endif

@ -60,11 +60,6 @@
#define BSD
#if defined(__HIGHC__) || \
(defined(__GNUC__) && (__GNUC__ < 4))
#define ssize_t int
#endif
/* Target HAVE_x section */
#if defined(DJGPP)

@ -216,20 +216,6 @@
#define HAVE_BOOL_T
#endif
/* Define if ssize_t is not an available 'typedefed' type. */
#ifndef _SSIZE_T_DEFINED
# if (defined(__WATCOMC__) && (__WATCOMC__ >= 1240)) || \
defined(__POCC__) || \
defined(__MINGW32__)
# elif defined(_WIN64)
# define _SSIZE_T_DEFINED
# define ssize_t __int64
# else
# define _SSIZE_T_DEFINED
# define ssize_t int
# endif
#endif
/* ---------------------------------------------------------------- */
/* TYPE SIZES */
/* ---------------------------------------------------------------- */

@ -557,8 +557,12 @@ fi
# check for ssize_t
AC_CHECK_TYPE(ssize_t, ,
AC_DEFINE(ssize_t, int, [the signed version of size_t]))
AC_CHECK_TYPE(ssize_t, [ CARES_TYPEOF_ARES_SSIZE_T=ssize_t ],
[ CARES_TYPEOF_ARES_SSIZE_T=int ])
AC_DEFINE_UNQUOTED([CARES_TYPEOF_ARES_SSIZE_T], ${CARES_TYPEOF_ARES_SSIZE_T},
[the signed version of size_t])
# check for bool type
AC_CHECK_TYPE([bool],[

@ -357,8 +357,8 @@ inet_net_pton_ipv6(const char *src, unsigned char *dst, size_t size)
* Since some memmove()'s erroneously fail to handle
* overlapping regions, we'll do the shift by hand.
*/
const ssize_t n = tp - colonp;
ssize_t i;
const ares_ssize_t n = tp - colonp;
ares_ssize_t i;
if (tp == endp)
goto enoent;

@ -131,7 +131,7 @@ struct timeval {
#if defined(__minix)
/* Minix doesn't support recv on TCP sockets */
#define sread(x,y,z) (ssize_t)read((RECV_TYPE_ARG1)(x), \
#define sread(x,y,z) (ares_ssize_t)read((RECV_TYPE_ARG1)(x), \
(RECV_TYPE_ARG2)(y), \
(RECV_TYPE_ARG3)(z))
@ -167,7 +167,7 @@ struct timeval {
Error Missing_definition_of_return_and_arguments_types_of_recv
/* */
#else
#define sread(x,y,z) (ssize_t)recv((RECV_TYPE_ARG1)(x), \
#define sread(x,y,z) (ares_ssize_t)recv((RECV_TYPE_ARG1)(x), \
(RECV_TYPE_ARG2)(y), \
(RECV_TYPE_ARG3)(z), \
(RECV_TYPE_ARG4)(0))
@ -183,7 +183,7 @@ struct timeval {
#if defined(__minix)
/* Minix doesn't support send on TCP sockets */
#define swrite(x,y,z) (ssize_t)write((SEND_TYPE_ARG1)(x), \
#define swrite(x,y,z) (ares_ssize_t)write((SEND_TYPE_ARG1)(x), \
(SEND_TYPE_ARG2)(y), \
(SEND_TYPE_ARG3)(z))
@ -198,7 +198,7 @@ struct timeval {
Error Missing_definition_of_return_and_arguments_types_of_send
/* */
#else
#define swrite(x,y,z) (ssize_t)send((SEND_TYPE_ARG1)(x), \
#define swrite(x,y,z) (ares_ssize_t)send((SEND_TYPE_ARG1)(x), \
(SEND_TYPE_ARG2)(y), \
(SEND_TYPE_ARG3)(z), \
(SEND_TYPE_ARG4)(SEND_4TH_ARG))
@ -228,7 +228,7 @@ struct timeval {
Error Missing_definition_of_return_and_arguments_types_of_recvfrom
/* */
#else
#define sreadfrom(s,b,bl,f,fl) (ssize_t)recvfrom((RECVFROM_TYPE_ARG1) (s), \
#define sreadfrom(s,b,bl,f,fl) (ares_ssize_t)recvfrom((RECVFROM_TYPE_ARG1) (s), \
(RECVFROM_TYPE_ARG2 *)(b), \
(RECVFROM_TYPE_ARG3) (bl), \
(RECVFROM_TYPE_ARG4) (0), \

Loading…
Cancel
Save