]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
add debug messages for fopen() failures
authorYang Tse <yangsita@gmail.com>
Fri, 16 Feb 2007 19:17:05 +0000 (19:17 +0000)
committerYang Tse <yangsita@gmail.com>
Fri, 16 Feb 2007 19:17:05 +0000 (19:17 +0000)
ares/ares_gethostbyaddr.c
ares/ares_search.c
tests/libtest/lib505.c
tests/libtest/lib525.c

index 41bf916bf62a5b6ad4bd2d08ead782ef73e44a1e..6c80eb941f603c06ba68622397e992b9be124660 100644 (file)
@@ -216,9 +216,26 @@ static int file_lookup(union ares_addr *addr, int family, struct hostent **host)
     return ARES_ENOTFOUND;
 #endif
 
+  int error;
+
   fp = fopen(PATH_HOSTS, "r");
   if (!fp)
-    return ARES_ENOTFOUND;
+    {
+      error = ERRNO;
+      switch(error) 
+        {
+        case ENOENT:
+          return ARES_ENOTFOUND;
+          break;
+        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;
+        }
+    }
   while ((status = ares__get_hostent(fp, family, host)) == ARES_SUCCESS)
     {
       if (family != (*host)->h_addrtype)
index b05b4a833f408a1404b70e1da17a7a6131e7a55d..e63afff0527e8d2fc5bd19889a94d5790e8e8618 100644 (file)
@@ -216,6 +216,7 @@ static int single_domain(ares_channel channel, const char *name, char **s)
   char *line = NULL;
   int linesize, status;
   const char *p, *q;
+  int error;
 
   /* If the name contains a trailing dot, then the single query is the name
    * sans the trailing dot.
@@ -265,6 +266,22 @@ static int single_domain(ares_channel channel, const char *name, char **s)
               if (status != ARES_SUCCESS)
                 return status;
             }
+          else 
+            {
+              error = ERRNO;
+              switch(error) 
+                {
+                case ENOENT:
+                  break;
+                default:
+                  DEBUGF(fprintf(stderr, "fopen() failed with error: %d %s\n",
+                                 error, strerror(error)));
+                  DEBUGF(fprintf(stderr, "Error opening file: %s\n", 
+                                 hostaliases));
+                  *s = NULL;
+                  return ARES_EFILE;
+                }
+            }
         }
     }
 
index 85ce38b3275e5c73b6631c2049234d5eda4fa004..098e8f9e063c22dea1a33b4080a5efbb0039d360 100644 (file)
@@ -43,6 +43,7 @@ int test(char *URL)
   int hd ;
   struct_stat file_info;
   struct curl_slist *hl;
+  int error;
 
   struct curl_slist *headerlist=NULL;
   const char *buf_1 = "RNFR 505";
@@ -57,6 +58,9 @@ int test(char *URL)
   hd = stat(arg2, &file_info);
   if(hd == -1) {
     /* can't open file, bail out */
+    error = ERRNO;
+    fprintf(stderr, "stat() failed with error: %d %s\n",
+            error, strerror(error));
     fprintf(stderr, "WARNING: cannot open file %s\n", arg2);
     return -1;
   }
@@ -71,6 +75,10 @@ int test(char *URL)
      an example! */
   hd_src = fopen(arg2, "rb");
   if(NULL == hd_src) {
+    error = ERRNO;
+    fprintf(stderr, "fopen() failed with error: %d %s\n",
+            error, strerror(error));
+    fprintf(stderr, "Error opening file: %s\n", arg2);
     return -2; /* if this happens things are major weird */
   }
 
index ce12b3b84cb67312a8d1d8ac0d204d404b1cc911..14e0c0c7621ffb9ebd1bca6e09b2464ccc10e6cf 100644 (file)
@@ -25,6 +25,7 @@ int test(char *URL)
   CURL *curl;
   FILE *hd_src ;
   int hd ;
+  int error;
   struct_stat file_info;
   int running;
   char done=FALSE;
@@ -48,6 +49,13 @@ int test(char *URL)
      fdopen() from the previous descriptor, but hey this is just
      an example! */
   hd_src = fopen(arg2, "rb");
+  if(NULL == hd_src) {
+    error = ERRNO;
+    fprintf(stderr, "fopen() failed with error: %d %s\n",
+            error, strerror(error));
+    fprintf(stderr, "Error opening file: %s\n", arg2);
+    return TEST_ERR_MAJOR_BAD;
+  }
 
   if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
     fprintf(stderr, "curl_global_init() failed\n");