ARES_LIBRARY_INIT(3)

πŸ“¦
version 1.34.9 Β· 4 versions
, in alpine 3.22, alpine 3.23, alpine 3.24, arch rolling, centos-stream 10, debian trixie, fedora 43, fedora 44, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’– ARES_LIBRARY_INIT(3) β€” Library Functions Manual πŸ’–

okay bestie, sit down, hydrate, because we're talking about ares_library_init β€” the c-ares library initialization function, and she is literally the first thing your program needs to talk to before literally anything else in c-ares even looks at you. main character energy, no cap. πŸŽ€


✨ NAME ✨

ares_library_init β€” c-ares library initialization, aka the vibe check your program has to pass before touching anything else 🌸


✨ SYNOPSIS ✨

#include <ares.h>

int ares_library_init(int flags)

int ares_library_init_mem(int flags,
                          void *(*amalloc)(size_t),
                          void (*afree)(void *ptr),
                          void (*arealloc)(void *ptr, size_t size))

✨ DESCRIPTION ✨

So. The ares_library_init function does all the internal setup stuff that the c-ares library needs, and it must happen before any other function c-ares gives you can be used in a program. Like, she's the pregame. Nobody skips the pregame. πŸ’…

This function has to be called at least once during the life of your program, and it has to happen before your program actually executes any other c-ares library function. The initializations she does stay in effect until you've made a number of calls to ares_library_cleanup(3) equal to the number of calls to this function. Math girlies rise β€” it's a matching pair situation. 🧚

Successive calls to this function do nothing further, bestie. Only the first call β€” the one made while c-ares is still in an uninitialized state β€” is actually effective. Everything after that is just her standing there, unbothered, serving looks. ✨

The flags parameter is a bit pattern that tells c-ares exactly which features should be initialized, described below. You set the bits you want by ORing the values together. In normal operation you should specify ARES_LIB_INIT_ALL. Don't use any other value unless you are familiar with it and you're trying to control some internal c-ares feature β€” that's deep-lore territory, iykyk. πŸ”₯

The ares_library_init_mem function lets the caller provide memory management functions that the c-ares library will use instead of malloc(3), free(3) and realloc(3). Custom allocator moment, we love a personalized touch. 🫢

⚠️ Not thread safe, bestie. You have to call it once the program has started, but this call must be done before the program starts any other thread. This is required to avoid potential race conditions in library initialization, and also because ares_library_init(3) might call functions from other libraries that are thread unsafe, and could conflict with any other thread that is already using these other libraries. Do not start the group chat before she's done talking. πŸ’€

On Windows platforms, the library user should ensure that WSAStartup() is called before the c-ares library is initialized and used.

Win32/64 application DLLs shall not call ares_library_init(3) from the DllMain function. Doing so will produce deadlocks and other problems. Not a cute look. Not the move. πŸ™ˆ


🌈 FLAGS 🌈

  • ARES_LIB_INIT_ALL β€” Initialize everything possible. This sets all known bits. She's doing the most and honestly? Correct. πŸ‘‘
  • ARES_LIB_INIT_WIN32 β€” Initialize Win32/64 specific libraries. As of c-ares 1.19.0, this is ignored as there are no currently dynamically loaded libraries. Retired but still in the yearbook. πŸ’œ
  • ARES_LIB_INIT_NONE β€” Initialize nothing extra. This sets no bit. The minimalist. The clean girl aesthetic of flags. 🌸

⭐ RETURN VALUE ⭐

Upon successful completion, ares_library_init(3) returns 0. Otherwise, a non-zero error number is returned to indicate the error.

🚨 And listen closely: except for ares_strerror(3), you shall not call any other c-ares function upon ares_library_init(3) failure. Only ares_strerror(3) gets a pass. That's the one bestie you're allowed to text back. 😭

πŸ¦‹ AVAILABILITY πŸ¦‹

This function was first introduced in c-ares version 1.7.0, along with the definition of preprocessor symbol CARES_HAVE_ARES_LIBRARY_INIT as an indication of the availability of this function. Its recursive behavior β€” which requires a matching number of calls to ares_library_cleanup(3) in order to deinitialize the library β€” is present since c-ares version 1.10.0. Earlier versions would deinitialize the library on the first call to ares_library_cleanup(3). Glow-up arc, fr fr. ✨

Since the introduction of this function it is absolutely mandatory to call it for any Win32/64 program using c-ares. No exceptions, periodt. πŸ’…

Non-Win32/64 systems can still use c-ares version 1.7.0 without calling ares_library_init(3) due to the fact that currently it is nearly a do-nothing function on non-Win32/64 platforms at this point. Lowkey she's just there for the vibes on those platforms. πŸŽ€


πŸ‘‘ SEE ALSO πŸ‘‘

ares_library_cleanup(3), ares_strerror(3)


and that's the whole page, bestie!! this one's from 19 May 2009, and it lives in the ARES_LIBRARY_INIT(3) corner of the manual. go call your cleanup the right number of times and stay hydrated πŸ«ΆπŸ’–βœ¨

πŸ“¦ where this page comes from