xref: /curl/docs/libcurl/curl_getenv.md (revision 3040971d)
1---
2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
3SPDX-License-Identifier: curl
4Title: curl_getenv
5Section: 3
6Source: libcurl
7See-also:
8  - getenv (3C)
9Protocol:
10  - All
11Added-in: 7.1
12---
13
14# NAME
15
16curl_getenv - return value for environment name
17
18# SYNOPSIS
19
20~~~c
21#include <curl/curl.h>
22
23char *curl_getenv(const char *name);
24~~~
25
26# DESCRIPTION
27
28curl_getenv() is a portable wrapper for the getenv() function, meant to
29emulate its behavior and provide an identical interface for all operating
30systems libcurl builds on (including Windows).
31
32You must curl_free(3) the returned string when you are done with it.
33
34# %PROTOCOLS%
35
36# EXAMPLE
37
38~~~c
39int main(void)
40{
41  char *width = curl_getenv("COLUMNS");
42  if(width) {
43    /* it was set */
44    curl_free(width);
45  }
46}
47~~~
48
49# %AVAILABILITY%
50
51# RETURN VALUE
52
53A pointer to a null-terminated string or NULL if it failed to find the
54specified name.
55
56# NOTE
57
58Under Unix operating systems, there is no point in returning an allocated
59memory, although other systems does not work properly if this is not done. The
60Unix implementation thus suffers slightly from the drawbacks of other systems.
61