tool_operate: Moved libcurl information gathering to tool_main
authorSteve Holme <steve_holme@hotmail.com>
Sun, 2 Feb 2014 15:11:22 +0000 (15:11 +0000)
committerSteve Holme <steve_holme@hotmail.com>
Mon, 3 Feb 2014 22:56:58 +0000 (22:56 +0000)
src/tool_main.c
src/tool_operate.c

index ba9b518..a46877b 100644 (file)
@@ -38,6 +38,7 @@
 #include "tool_panykey.h"
 #include "tool_vms.h"
 #include "tool_main.h"
+#include "tool_libinfo.h"
 
 /*
  * This is low-level hard-hacking memory leak tracking and similar. Using
@@ -120,14 +121,28 @@ static void memory_tracking_init(void)
  * _any_ libcurl usage. If this fails, *NO* libcurl functions may be
  * used, or havoc may be the result.
  */
-static CURLcode main_init(void)
+static CURLcode main_init(struct Configurable *config)
 {
+  CURLcode result = CURLE_OK;
+
 #if defined(__DJGPP__) || defined(__GO32__)
   /* stop stat() wasting time */
   _djstat_flags |= _STAT_INODE | _STAT_EXEC_MAGIC | _STAT_DIRSIZE;
 #endif
 
-  return curl_global_init(CURL_GLOBAL_DEFAULT);
+  /* Perform the libcurl initialization */
+  result = curl_global_init(CURL_GLOBAL_DEFAULT);
+  if(!result) {
+    /* Get information about libcurl */
+    result = get_libcurl_info();
+
+    if(result)
+      helpf(config->errors, "error retrieving curl library information\n");
+  }
+  else
+    helpf(config->errors, "error initializing curl library\n");
+
+  return result;
 }
 
 /*
@@ -167,17 +182,14 @@ int main(int argc, char *argv[])
 
     /* Initialize the curl library - do not call any libcurl functions before
        this point */
-    if(!main_init()) {
+    res = main_init(config);
+    if(!res) {
       /* Start our curl operation */
       res = operate(config, argc, argv);
 
       /* Perform the main cleanup */
       main_free();
     }
-    else {
-      helpf(config->errors, "error initializing curl library\n");
-      res = CURLE_FAILED_INIT;
-    }
 
 #ifdef __SYMBIAN32__
     if(config->showerror)
index af9e1de..5cdecd9 100644 (file)
@@ -212,12 +212,6 @@ int operate(struct Configurable *config, int argc, argv_item_t argv[])
   heads.stream = stdout;
   heads.config = config;
 
-  /* Get libcurl info right away */
-  if(get_libcurl_info() != CURLE_OK) {
-    helpf(config->errors, "error retrieving curl library information\n");
-    return CURLE_FAILED_INIT;
-  }
-
   /* Get a curl handle to use for all forthcoming curl transfers */
   curl = curl_easy_init();
   if(!curl) {