CURLINFO_OS_ERRNO(3)

πŸ’… CURLINFO_OS_ERRNO β€” bestie edition ✨

Okay so this is a page from the libcurl manual, section 3 (library functions). Buckle up, we're learning how to grab the raw errno from the last time a connect went sideways. 🫢


🌸 NAME 🌸

CURLINFO_OS_ERRNO β€” literally the errno number from your last connect failure, no cap πŸ’€

✨ SYNOPSIS ✨

#include <curl/curl.h>

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

πŸ¦‹ DESCRIPTION πŸ¦‹

So you pass in a pointer to a long, right? And it receives the errno variable from a connect failure. That's the vibe. πŸ’«

⚠️ The way that this value is only set on failure β€” it is not reset when an operation succeeds. So don't go thinking a stale number means something happened just now, bestie. πŸ™ˆ

Also the number is OS and system specific, so like, what you get on one machine is not what you get on another. iykyk.

The libcurl network-related errors that may have a saved errno are, and I'm listing all of them because we don't skip:

  • CURLE_COULDNT_CONNECT
  • CURLE_FAILED_INIT
  • CURLE_INTERFACE_FAILED
  • CURLE_OPERATION_TIMEDOUT
  • CURLE_RECV_ERROR
  • CURLE_SEND_ERROR

And here's the glow-up moment πŸŽ€: since 8.8.0 libcurl clears the easy handle's saved errno before performing the transfer. Prior versions did not clear the saved errno, which means if a saved errno is retrieved it could be from a previous transfer on the same handle. Iconic little footgun, honestly. 😭

🌈 PROTOCOLS 🌈

This functionality affects all supported protocols. All of them. Every single one. periodt. πŸ‘‘

πŸ“ EXAMPLE πŸ“

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

πŸ’œ AVAILABILITY πŸ’œ

Added in curl 7.12.2 β€” vintage but still slaying ✨

πŸŽ€ RETURN VALUE πŸŽ€

curl_easy_getinfo(3) returns a CURLcode indicating success or error.

  • CURLE_OK (0) means everything was OK πŸ’–
  • non-zero means an error occurred β€” see libcurl-errors(3) for the deets

πŸ”₯ SEE ALSO πŸ”₯


✨ that's the whole page, bestie ✨ β€” brought to you by the libcurl manual, dated 2026-10-12. Go get those errnos. πŸ’…πŸ¦‹

πŸ“¦ where this page comes from