GNURLINFO_OS_ERRNO(3)

πŸ“¦ version 7.72.0, in nixos 26.05, nixpkgs unstable

πŸ’… GNURLINFO_OS_ERRNO(3) β€” like, the curl_easy_getinfo options era πŸŽ€

okay bestie, so this one lives in the curl_easy_getinfo options family (that's the manual name, iykyk) and it's literally about catching the errno from a failed connect. let's get into it ✨


🌸 NAME 🌸

CURLINFO_OS_ERRNO β€” grab the errno number from the last connect failure 🫢


✨ SYNOPSIS ✨

#include <gnurl/curl.h>

CURLcode curl_easy_getinfo(CURL *handle, CURLINFO_OS_ERRNO, long *errnop);

like, that's the whole vibe. you hand it a long pointer and it fills it in πŸŽ€


πŸ’– DESCRIPTION πŸ’–

so here's the tea: you pass a pointer to a long, and it receives the errno variable from a connect failure. that's it, that's the whole thing πŸ’…

⚠️ important caveat, no cap: the value is only set on failure. it is not reset when an operation succeeds. so if you're out here reading it after a win, you're reading stale vibes, bestie 😭

also highkey relevant: the number is OS and system specific. so like, don't go comparing it across machines expecting matching energy 🌈


πŸ¦‹ PROTOCOLS πŸ¦‹

All πŸ‘‘


πŸ“ EXAMPLE πŸ“

CURL *curl = curl_easy_init();
if(curl) {
  CURLcode res;
  curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");
  res = curl_easy_perform(curl);
  if(res != CURLE_OK) {
    long error;
    res = curl_easy_getinfo(curl, CURLINFO_OS_ERRNO, &error);
    if(res && error) {
      printf("Errno: %ld\n", error);
    }
  }
  curl_easy_cleanup(curl);
}

look at that little if(res && error) check doing its main character thing πŸ”₯


⭐ AVAILABILITY ⭐

added in 7.12.2 β€” vintage but iconic, fr fr πŸŽ€


πŸ’œ RETURN VALUE πŸ’œ

  • returns CURLE_OK if the option is supported βœ…
  • returns CURLE_UNKNOWN_OPTION if it's not πŸ™ˆ

that's the whole vibe check.


🌟 SEE ALSO 🌟


okay that's the page!! mwah πŸ’‹ this was libcurl 7.44.0, dated 1 Sep 2015, and yes she's giving GNURLINFO_OS_ERRNO(3) energy the whole way through β€” go forth and debug your connects, bestie πŸ§šβ€β™€οΈπŸ’–

πŸ“¦ where this page comes from