Skip to content

Instantly share code, notes, and snippets.

@piscisaureus
Created February 2, 2012 13:12
Show Gist options
  • Save piscisaureus/1723401 to your computer and use it in GitHub Desktop.
Save piscisaureus/1723401 to your computer and use it in GitHub Desktop.
From c073686cbf7f6292e64bd687ab8c25ea3ae6b10e Mon Sep 17 00:00:00 2001
From: Bert Belder <[email protected]>
Date: Thu, 26 Jan 2012 18:52:04 +0100
Subject: [PATCH 1/1] c-ares error report
---
deps/c-ares/ares__read_line.c | 9 +++++++--
deps/c-ares/ares_gethostbyname.c | 25 +++++++++++--------------
2 files changed, 18 insertions(+), 16 deletions(-)
diff --git a/deps/c-ares/ares__read_line.c b/deps/c-ares/ares__read_line.c
index ca01803..2a71507 100644
--- a/deps/c-ares/ares__read_line.c
+++ b/deps/c-ares/ares__read_line.c
@@ -48,8 +48,13 @@ int ares__read_line(FILE *fp, char **buf, size_t *bufsize)
{
int bytestoread = aresx_uztosi(*bufsize - offset);
- if (!fgets(*buf + offset, bytestoread, fp))
- return (offset != 0) ? 0 : (ferror(fp)) ? ARES_EFILE : ARES_EOF;
+ if (!fgets(*buf + offset, bytestoread, fp)) {
+ int error = ERRNO;
+ if (feof(fp)) return (offset != 0) ? 0 : ARES_EOF;
+ fprintf(stderr, "fgets() failed with error: %d %s\n",
+ error, strerror(error));
+ return ARES_EFILE;
+ }
len = offset + strlen(*buf + offset);
if ((*buf)[len - 1] == '\n')
{
diff --git a/deps/c-ares/ares_gethostbyname.c b/deps/c-ares/ares_gethostbyname.c
index 4469ffe..f9b189a 100644
--- a/deps/c-ares/ares_gethostbyname.c
+++ b/deps/c-ares/ares_gethostbyname.c
@@ -375,19 +375,12 @@ static int file_lookup(const char *name, int family, struct hostent **host)
if (!fp)
{
error = ERRNO;
- switch(error)
- {
- case ENOENT:
- case ESRCH:
- return ARES_ENOTFOUND;
- default:
- DEBUGF(fprintf(stderr, "fopen() failed with error: %d %s\n",
- error, strerror(error)));
- DEBUGF(fprintf(stderr, "Error opening file: %s\n",
- PATH_HOSTS));
- *host = NULL;
- return ARES_EFILE;
- }
+ fprintf(stderr, "fopen() failed with error: %d %s\n",
+ error, strerror(error));
+ fprintf(stderr, "Error opening file: %s\n",
+ PATH_HOSTS);
+ *host = NULL;
+ return ARES_EFILE;
}
while ((status = ares__get_hostent(fp, family, host)) == ARES_SUCCESS)
{
@@ -402,7 +395,11 @@ static int file_lookup(const char *name, int family, struct hostent **host)
break;
ares_free_hostent(*host);
}
- fclose(fp);
+ if (fclose(fp)) {
+ error = ERRNO;
+ fprintf(stderr, "fclose() failed with error: %d %s\n",
+ error, strerror(error));
+ }
if (status == ARES_EOF)
status = ARES_ENOTFOUND;
if (status != ARES_SUCCESS)
--
1.7.5.4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment