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_CONNECTCURLE_FAILED_INITCURLE_INTERFACE_FAILEDCURLE_OPERATION_TIMEDOUTCURLE_RECV_ERRORCURLE_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
- fedora 44: libcurl-devel 8.18.0-14.fc44 Β· curl
- fedora 44: libcurl-devel 8.18.0-14.fc44 Β· curl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms