curl / Mailing Lists / curl-library / Single Mail

curl-library

Is it safe to call `curl_global_init` before main()?

From: <curl.greatwolf_at_mamber.net>
Date: Wed, 12 Apr 2017 16:10:39 -0700

Just a quick question and the title pretty much covers it.

Is it okay to call `curl_global_init` and `curl_global_cleanup` before and
after main() respectively?

What I'd like to be able to do is perform the curl global state init using
C++ class ctor/dtor and static global variables. eg.

    class curl_startup_init
    {
      curl_startup_init() { curl_global_init(CURL_GLOBAL_ALL); }
      ~curl_startup_init() { curl_global_cleanup(); }
      static curl_startup_init _C;
    };
    curl_startup_init curl_startup_init::_C;

I want to move curl's global init outside of main into a different
translation unit to
better contain related code.

Now I didn't see much mention about init'ing curl in this fashion, only
that the doc states
`curl_global_init` needs to called prior to creating a curl handle and
invoking the other functions.
It would be great to get some clarification on whether the above idea is
safe to do.

Thanks

-------------------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2017-04-13