xref: /curl/docs/libcurl/opts/CURLINFO_OS_ERRNO.md (revision e3fe0200)
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
32# EXAMPLE
33
34~~~c
35int main(void)
36{
37  CURL *curl = curl_easy_init();
38  if(curl) {
39    CURLcode res;
40    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
41    res = curl_easy_perform(curl);
42    if(res != CURLE_OK) {
43      long error;
44      res = curl_easy_getinfo(curl, CURLINFO_OS_ERRNO, &error);
45      if(res && error) {
46        printf("Errno: %ld\n", error);
47      }
48    }
49    curl_easy_cleanup(curl);
50  }
51}
52~~~
53
54# AVAILABILITY
55
56Added in 7.12.2
57
58# RETURN VALUE
59
60Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not.
61