aboutsummaryrefslogtreecommitdiff
path: root/src/tool_main.c
diff options
context:
space:
mode:
authorSteve Holme <steve_holme@hotmail.com>2014-02-02 14:21:53 +0000
committerSteve Holme <steve_holme@hotmail.com>2014-02-03 12:31:16 +0000
commitb811200f647ba465e3e43ab7bdb42aa0fa671c98 (patch)
tree748b7ecdcc479da96979e72c1f2289a9a3893bcc /src/tool_main.c
parentc1daf6c0cd6c8a3f785ffa5cbdd228eb32fbf472 (diff)
tool_operate: Moved main initialisation and cleanup code into tool_main
Diffstat (limited to 'src/tool_main.c')
-rw-r--r--src/tool_main.c41
1 files changed, 39 insertions, 2 deletions
diff --git a/src/tool_main.c b/src/tool_main.c
index 5682bd78e..ba9b518e1 100644
--- a/src/tool_main.c
+++ b/src/tool_main.c
@@ -116,6 +116,32 @@ static void memory_tracking_init(void)
#endif
/*
+ * This is the main global constructor for the app. Call this before
+ * _any_ libcurl usage. If this fails, *NO* libcurl functions may be
+ * used, or havoc may be the result.
+ */
+static CURLcode main_init(void)
+{
+#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);
+}
+
+/*
+ * This is the main global destructor for the app. Call this after
+ * _all_ libcurl usage is done.
+ */
+static void main_free(void)
+{
+ curl_global_cleanup();
+ convert_cleanup();
+ metalink_cleanup();
+}
+
+/*
** curl tool main function.
*/
int main(int argc, char *argv[])
@@ -139,8 +165,19 @@ int main(int argc, char *argv[])
/* Initialise the config */
init_config(config);
- /* Start our curl operation */
- res = operate(config, argc, argv);
+ /* Initialize the curl library - do not call any libcurl functions before
+ this point */
+ if(!main_init()) {
+ /* 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)