VirtualBox

source: vbox/trunk/src/libs/curl-8.7.1/lib/getenv.c@ 106165

最後變更 在這個檔案從106165是 104083,由 vboxsync 提交於 8 月 前

curl-8.7.1: Applied and adjusted our curl changes to 8.4.0. bugref:10639

  • 屬性 svn:eol-style 設為 native
檔案大小: 2.3 KB
 
1/***************************************************************************
2 * _ _ ____ _
3 * Project ___| | | | _ \| |
4 * / __| | | | |_) | |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
7 *
8 * Copyright (C) Daniel Stenberg, <[email protected]>, et al.
9 *
10 * This software is licensed as described in the file COPYING, which
11 * you should have received as part of this distribution. The terms
12 * are also available at https://curl.se/docs/copyright.html.
13 *
14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 * copies of the Software, and permit persons to whom the Software is
16 * furnished to do so, under the terms of the COPYING file.
17 *
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
20 *
21 * SPDX-License-Identifier: curl
22 *
23 ***************************************************************************/
24
25#include "curl_setup.h"
26
27#include <curl/curl.h>
28#include "curl_memory.h"
29
30#include "memdebug.h"
31
32static char *GetEnv(const char *variable)
33{
34#if defined(_WIN32_WCE) || defined(CURL_WINDOWS_APP) || \
35 defined(__ORBIS__) || defined(__PROSPERO__) /* PlayStation 4 and 5 */
36 (void)variable;
37 return NULL;
38#elif defined(_WIN32)
39 /* This uses Windows API instead of C runtime getenv() to get the environment
40 variable since some changes aren't always visible to the latter. #4774 */
41 char *buf = NULL;
42 char *tmp;
43 DWORD bufsize;
44 DWORD rc = 1;
45 const DWORD max = 32768; /* max env var size from MSCRT source */
46
47 for(;;) {
48 tmp = realloc(buf, rc);
49 if(!tmp) {
50 free(buf);
51 return NULL;
52 }
53
54 buf = tmp;
55 bufsize = rc;
56
57 /* It's possible for rc to be 0 if the variable was found but empty.
58 Since getenv doesn't make that distinction we ignore it as well. */
59 rc = GetEnvironmentVariableA(variable, buf, bufsize);
60 if(!rc || rc == bufsize || rc > max) {
61 free(buf);
62 return NULL;
63 }
64
65 /* if rc < bufsize then rc is bytes written not including null */
66 if(rc < bufsize)
67 return buf;
68
69 /* else rc is bytes needed, try again */
70 }
71#else
72 char *env = getenv(variable);
73 return (env && env[0])?strdup(env):NULL;
74#endif
75}
76
77char *curl_getenv(const char *v)
78{
79 return GetEnv(v);
80}
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette