1--- 2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 3SPDX-License-Identifier: curl 4Title: CURLINFO_OS_ERRNO 5Section: 3 6Source: libcurl 7See-also: 8 - curl_easy_getinfo (3) 9 - curl_easy_setopt (3) 10Protocol: 11 - All 12--- 13 14# NAME 15 16CURLINFO_OS_ERRNO - get errno number from last connect failure 17 18# SYNOPSIS 19 20~~~c 21#include <curl/curl.h> 22 23CURLcode curl_easy_getinfo(CURL *handle, CURLINFO_OS_ERRNO, long *errnop); 24~~~ 25 26# DESCRIPTION 27 28Pass a pointer to a long to receive the errno variable from a connect failure. 29Note that the value is only set on failure, it is not reset upon a successful 30operation. The number is OS and system specific. 31 32libcurl network-related errors that may have a saved errno are: 33CURLE_COULDNT_CONNECT, CURLE_FAILED_INIT, CURLE_INTERFACE_FAILED, 34CURLE_OPERATION_TIMEDOUT, CURLE_RECV_ERROR, CURLE_SEND_ERROR. 35 36Since 8.8.0 libcurl clears the easy handle's saved errno before performing the 37transfer. Prior versions did not clear the saved errno, which means if a saved 38errno is retrieved it could be from a previous transfer on the same handle. 39 40# EXAMPLE 41 42~~~c 43int main(void) 44{ 45 CURL *curl = curl_easy_init(); 46 if(curl) { 47 CURLcode res; 48 curl_easy_setopt(curl, CURLOPT_URL, "https://example.com"); 49 res = curl_easy_perform(curl); 50 if(res != CURLE_OK) { 51 long error; 52 res = curl_easy_getinfo(curl, CURLINFO_OS_ERRNO, &error); 53 if(!res && error) { 54 printf("Errno: %ld\n", error); 55 } 56 } 57 curl_easy_cleanup(curl); 58 } 59} 60~~~ 61 62# AVAILABILITY 63 64Added in 7.12.2 65 66# RETURN VALUE 67 68Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not. 69