mirror of
https://github.com/moparisthebest/curl
synced 2024-12-22 08:08:50 -05:00
use macros ERRNO, SET_ERRNO(), SOCKERRNO and SET_SOCKERRNO() for errno handling
This commit is contained in:
parent
9896421586
commit
059b57677c
@ -289,7 +289,7 @@ int main(int argc, char **argv)
|
||||
break;
|
||||
tvp = ares_timeout(channel, NULL, &tv);
|
||||
count = select(nfds, &read_fds, &write_fds, NULL, tvp);
|
||||
if (count < 0 && errno != EINVAL)
|
||||
if (count < 0 && SOCKERRNO != EINVAL)
|
||||
{
|
||||
perror("select");
|
||||
return 1;
|
||||
|
@ -610,6 +610,7 @@ DhcpNameServer
|
||||
char *p;
|
||||
FILE *fp;
|
||||
int linesize;
|
||||
int error;
|
||||
|
||||
fp = fopen(PATH_RESOLV_CONF, "r");
|
||||
if (fp) {
|
||||
@ -635,13 +636,14 @@ DhcpNameServer
|
||||
fclose(fp);
|
||||
}
|
||||
else {
|
||||
switch(errno) {
|
||||
error = ERRNO;
|
||||
switch(error) {
|
||||
case ENOENT:
|
||||
status = ARES_EOF;
|
||||
break;
|
||||
default:
|
||||
DEBUGF(fprintf(stderr, "fopen() failed with error: %d %s\n",
|
||||
errno, strerror(errno)));
|
||||
error, strerror(error)));
|
||||
DEBUGF(fprintf(stderr, "Error opening file: %s\n", PATH_RESOLV_CONF));
|
||||
status = ARES_EFILE;
|
||||
}
|
||||
@ -659,13 +661,14 @@ DhcpNameServer
|
||||
fclose(fp);
|
||||
}
|
||||
else {
|
||||
switch(errno) {
|
||||
error = ERRNO;
|
||||
switch(error) {
|
||||
case ENOENT:
|
||||
status = ARES_EOF;
|
||||
break;
|
||||
default:
|
||||
DEBUGF(fprintf(stderr, "fopen() failed with error: %d %s\n",
|
||||
errno, strerror(errno)));
|
||||
error, strerror(error)));
|
||||
DEBUGF(fprintf(stderr, "Error opening file: %s\n", "/etc/nsswitch.conf"));
|
||||
status = ARES_EFILE;
|
||||
}
|
||||
@ -684,13 +687,14 @@ DhcpNameServer
|
||||
fclose(fp);
|
||||
}
|
||||
else {
|
||||
switch(errno) {
|
||||
error = ERRNO;
|
||||
switch(error) {
|
||||
case ENOENT:
|
||||
status = ARES_EOF;
|
||||
break;
|
||||
default:
|
||||
DEBUGF(fprintf(stderr, "fopen() failed with error: %d %s\n",
|
||||
errno, strerror(errno)));
|
||||
error, strerror(error)));
|
||||
DEBUGF(fprintf(stderr, "Error opening file: %s\n", "/etc/host.conf"));
|
||||
status = ARES_EFILE;
|
||||
}
|
||||
@ -709,13 +713,14 @@ DhcpNameServer
|
||||
fclose(fp);
|
||||
}
|
||||
else {
|
||||
switch(errno) {
|
||||
error = ERRNO;
|
||||
switch(error) {
|
||||
case ENOENT:
|
||||
status = ARES_EOF;
|
||||
break;
|
||||
default:
|
||||
DEBUGF(fprintf(stderr, "fopen() failed with error: %d %s\n",
|
||||
errno, strerror(errno)));
|
||||
error, strerror(error)));
|
||||
DEBUGF(fprintf(stderr, "Error opening file: %s\n", "/etc/svc.conf"));
|
||||
status = ARES_EFILE;
|
||||
}
|
||||
|
@ -59,12 +59,6 @@
|
||||
#define TRUE 1
|
||||
#endif
|
||||
|
||||
#ifdef USE_WINSOCK
|
||||
#define GET_ERRNO() WSAGetLastError()
|
||||
#else
|
||||
#define GET_ERRNO() errno
|
||||
#endif
|
||||
|
||||
static int try_again(int errnum);
|
||||
static void write_tcp_data(ares_channel channel, fd_set *write_fds,
|
||||
time_t now);
|
||||
@ -97,7 +91,7 @@ void ares_process(ares_channel channel, fd_set *read_fds, fd_set *write_fds)
|
||||
process_timeouts(channel, now);
|
||||
}
|
||||
|
||||
/* Return 1 if the specified errno describes a readiness error, or 0
|
||||
/* Return 1 if the specified error number describes a readiness error, or 0
|
||||
* otherwise. This is mostly for HP-UX, which could return EAGAIN or
|
||||
* EWOULDBLOCK. See this man page
|
||||
*
|
||||
@ -164,7 +158,7 @@ static void write_tcp_data(ares_channel channel, fd_set *write_fds, time_t now)
|
||||
free(vec);
|
||||
if (wcount < 0)
|
||||
{
|
||||
if (!try_again(GET_ERRNO()))
|
||||
if (!try_again(SOCKERRNO))
|
||||
handle_error(channel, i, now);
|
||||
continue;
|
||||
}
|
||||
@ -200,7 +194,7 @@ static void write_tcp_data(ares_channel channel, fd_set *write_fds, time_t now)
|
||||
scount = swrite(server->tcp_socket, sendreq->data, sendreq->len);
|
||||
if (scount < 0)
|
||||
{
|
||||
if (!try_again(GET_ERRNO()))
|
||||
if (!try_again(SOCKERRNO))
|
||||
handle_error(channel, i, now);
|
||||
continue;
|
||||
}
|
||||
@ -253,7 +247,7 @@ static void read_tcp_data(ares_channel channel, fd_set *read_fds, time_t now)
|
||||
2 - server->tcp_lenbuf_pos);
|
||||
if (count <= 0)
|
||||
{
|
||||
if (!(count == -1 && try_again(GET_ERRNO())))
|
||||
if (!(count == -1 && try_again(SOCKERRNO)))
|
||||
handle_error(channel, i, now);
|
||||
continue;
|
||||
}
|
||||
@ -280,7 +274,7 @@ static void read_tcp_data(ares_channel channel, fd_set *read_fds, time_t now)
|
||||
server->tcp_length - server->tcp_buffer_pos);
|
||||
if (count <= 0)
|
||||
{
|
||||
if (!(count == -1 && try_again(GET_ERRNO())))
|
||||
if (!(count == -1 && try_again(SOCKERRNO)))
|
||||
handle_error(channel, i, now);
|
||||
continue;
|
||||
}
|
||||
@ -322,7 +316,7 @@ static void read_udp_packets(ares_channel channel, fd_set *read_fds,
|
||||
continue;
|
||||
|
||||
count = sread(server->udp_socket, buf, sizeof(buf));
|
||||
if (count == -1 && try_again(GET_ERRNO()))
|
||||
if (count == -1 && try_again(SOCKERRNO))
|
||||
continue;
|
||||
else if (count <= 0)
|
||||
handle_error(channel, i, now);
|
||||
@ -615,7 +609,7 @@ static int open_tcp_socket(ares_channel channel, struct server_state *server)
|
||||
sockin.sin_addr = server->addr;
|
||||
sockin.sin_port = (unsigned short)(channel->tcp_port & 0xffff);
|
||||
if (connect(s, (struct sockaddr *) &sockin, sizeof(sockin)) == -1) {
|
||||
int err = GET_ERRNO();
|
||||
int err = SOCKERRNO;
|
||||
|
||||
if (err != EINPROGRESS && err != EWOULDBLOCK) {
|
||||
closesocket(s);
|
||||
|
@ -66,6 +66,11 @@
|
||||
* note:
|
||||
* network byte order assumed. this means 192.5.5.240/28 has
|
||||
* 0b11110000 in its fourth octet.
|
||||
* note:
|
||||
* On Windows we store the error in the thread errno, not
|
||||
* in the winsock error code. This is to avoid loosing the
|
||||
* actual last winsock error. So use macro ERRNO to fetch the
|
||||
* errno this funtion sets when returning (-1), not SOCKERRNO.
|
||||
* author:
|
||||
* Paul Vixie (ISC), June 1996
|
||||
*/
|
||||
@ -186,11 +191,11 @@ inet_net_pton_ipv4(const char *src, unsigned char *dst, size_t size)
|
||||
return (bits);
|
||||
|
||||
enoent:
|
||||
errno = ENOENT;
|
||||
SET_ERRNO(ENOENT);
|
||||
return (-1);
|
||||
|
||||
emsgsize:
|
||||
errno = EMSGSIZE;
|
||||
SET_ERRNO(EMSGSIZE);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
@ -381,11 +386,11 @@ inet_net_pton_ipv6(const char *src, unsigned char *dst, size_t size)
|
||||
return (bits);
|
||||
|
||||
enoent:
|
||||
errno = ENOENT;
|
||||
SET_ERRNO(ENOENT);
|
||||
return (-1);
|
||||
|
||||
emsgsize:
|
||||
errno = EMSGSIZE;
|
||||
SET_ERRNO(EMSGSIZE);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
@ -399,6 +404,11 @@ inet_net_pton_ipv6(const char *src, unsigned char *dst, size_t size)
|
||||
* number of bits, either imputed classfully or specified with /CIDR,
|
||||
* or -1 if some failure occurred (check errno). ENOENT means it was
|
||||
* not a valid network specification.
|
||||
* note:
|
||||
* On Windows we store the error in the thread errno, not
|
||||
* in the winsock error code. This is to avoid loosing the
|
||||
* actual last winsock error. So use macro ERRNO to fetch the
|
||||
* errno this funtion sets when returning (-1), not SOCKERRNO.
|
||||
* author:
|
||||
* Paul Vixie (ISC), June 1996
|
||||
*/
|
||||
@ -411,7 +421,7 @@ ares_inet_net_pton(int af, const char *src, void *dst, size_t size)
|
||||
case AF_INET6:
|
||||
return (inet_net_pton_ipv6(src, dst, size));
|
||||
default:
|
||||
errno = EAFNOSUPPORT;
|
||||
SET_ERRNO(EAFNOSUPPORT);
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
@ -429,11 +439,11 @@ int ares_inet_pton(int af, const char *src, void *dst)
|
||||
size = sizeof(struct in6_addr);
|
||||
else
|
||||
{
|
||||
errno = EAFNOSUPPORT;
|
||||
SET_ERRNO(EAFNOSUPPORT);
|
||||
return -1;
|
||||
}
|
||||
result = ares_inet_net_pton(af, src, dst, size);
|
||||
if (result == -1 && errno == ENOENT)
|
||||
if (result == -1 && ERRNO == ENOENT)
|
||||
return 0;
|
||||
return (result > -1 ? 1 : -1);
|
||||
}
|
||||
|
@ -68,6 +68,11 @@ static const char *inet_ntop6(const unsigned char *src, char *dst, size_t size);
|
||||
* convert a network format address to presentation format.
|
||||
* return:
|
||||
* pointer to presentation format address (`dst'), or NULL (see errno).
|
||||
* note:
|
||||
* On Windows we store the error in the thread errno, not
|
||||
* in the winsock error code. This is to avoid loosing the
|
||||
* actual last winsock error. So use macro ERRNO to fetch the
|
||||
* errno this funtion sets when returning NULL, not SOCKERRNO.
|
||||
* author:
|
||||
* Paul Vixie, 1996.
|
||||
*/
|
||||
@ -81,7 +86,7 @@ ares_inet_ntop(int af, const void *src, char *dst, size_t size)
|
||||
case AF_INET6:
|
||||
return (inet_ntop6(src, dst, size));
|
||||
default:
|
||||
errno = EAFNOSUPPORT;
|
||||
SET_ERRNO(EAFNOSUPPORT);
|
||||
return (NULL);
|
||||
}
|
||||
/* NOTREACHED */
|
||||
@ -106,7 +111,7 @@ inet_ntop4(const unsigned char *src, char *dst, size_t size)
|
||||
|
||||
if (SPRINTF((tmp, fmt, src[0], src[1], src[2], src[3])) > size)
|
||||
{
|
||||
errno = ENOSPC;
|
||||
SET_ERRNO(ENOSPC);
|
||||
return (NULL);
|
||||
}
|
||||
strcpy(dst, tmp);
|
||||
@ -218,7 +223,7 @@ inet_ntop6(const unsigned char *src, char *dst, size_t size)
|
||||
*/
|
||||
if ((size_t)(tp - tmp) > size)
|
||||
{
|
||||
errno = ENOSPC;
|
||||
SET_ERRNO(ENOSPC);
|
||||
return (NULL);
|
||||
}
|
||||
strcpy(dst, tmp);
|
||||
|
@ -105,7 +105,7 @@ ares_writev (ares_socket_t s, const struct iovec *vector, size_t count)
|
||||
buffer = bp = (char*) alloca (bytes);
|
||||
if (!buffer)
|
||||
{
|
||||
errno = ENOMEM;
|
||||
SET_ERRNO(ENOMEM);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user