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;
char *p;
FILE *fp;
int linesize;
+ int error;
fp = fopen(PATH_RESOLV_CONF, "r");
if (fp) {
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;
}
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;
}
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;
}
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;
}
#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);
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
*
free(vec);
if (wcount < 0)
{
- if (!try_again(GET_ERRNO()))
+ if (!try_again(SOCKERRNO))
handle_error(channel, i, now);
continue;
}
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;
}
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;
}
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;
}
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);
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);
* 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
*/
return (bits);
enoent:
- errno = ENOENT;
+ SET_ERRNO(ENOENT);
return (-1);
emsgsize:
- errno = EMSGSIZE;
+ SET_ERRNO(EMSGSIZE);
return (-1);
}
return (bits);
enoent:
- errno = ENOENT;
+ SET_ERRNO(ENOENT);
return (-1);
emsgsize:
- errno = EMSGSIZE;
+ SET_ERRNO(EMSGSIZE);
return (-1);
}
* 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
*/
case AF_INET6:
return (inet_net_pton_ipv6(src, dst, size));
default:
- errno = EAFNOSUPPORT;
+ SET_ERRNO(EAFNOSUPPORT);
return (-1);
}
}
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);
}
* 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.
*/
case AF_INET6:
return (inet_ntop6(src, dst, size));
default:
- errno = EAFNOSUPPORT;
+ SET_ERRNO(EAFNOSUPPORT);
return (NULL);
}
/* NOTREACHED */
if (SPRINTF((tmp, fmt, src[0], src[1], src[2], src[3])) > size)
{
- errno = ENOSPC;
+ SET_ERRNO(ENOSPC);
return (NULL);
}
strcpy(dst, tmp);
*/
if ((size_t)(tp - tmp) > size)
{
- errno = ENOSPC;
+ SET_ERRNO(ENOSPC);
return (NULL);
}
strcpy(dst, tmp);
buffer = bp = (char*) alloca (bytes);
if (!buffer)
{
- errno = ENOMEM;
+ SET_ERRNO(ENOMEM);
return (-1);
}