diff --git a/build.sh b/build.sh index eb7fb35..0a9cc0c 100644 --- a/build.sh +++ b/build.sh @@ -204,6 +204,7 @@ readonly CURL_DIR="${BASE_DIR}/curl-${MY_CPU}" rm -rf "${CURL_DIR}" && mkdir "${CURL_DIR}" tar -xvf "${LIBS_DIR}/.pkg/curl.tar.gz" --strip-components=1 -C "${CURL_DIR}" pushd "${CURL_DIR}" +patch -p1 -b < "${BASE_DIR}/patch/curl_getenv.diff" patch -p1 -b < "${BASE_DIR}/patch/curl_threads.diff" patch -p1 -b < "${BASE_DIR}/patch/curl_tool_doswin.diff" patch -p1 -b < "${BASE_DIR}/patch/curl_tool_parsecfg.diff" diff --git a/patch/curl_getenv.diff b/patch/curl_getenv.diff new file mode 100644 index 0000000..4b9596c --- /dev/null +++ b/patch/curl_getenv.diff @@ -0,0 +1,78 @@ +diff --git "a/D:\\_Sandbox\\curl\\curl-x86\\lib\\getenv.c.orig" "b/D:\\_Sandbox\\curl\\curl-x86\\lib\\getenv.c" +index 92c5350..f73d00b 100644 +--- "a/lib/getenv.c" ++++ "b/lib/getenv.c" +@@ -27,22 +27,19 @@ + + #include "memdebug.h" + +-static char *GetEnv(const char *variable) ++#ifdef WIN32 ++static TCHAR *GetEnvWin32(const TCHAR *variable) + { +-#if defined(_WIN32_WCE) || defined(CURL_WINDOWS_APP) +- (void)variable; +- return NULL; +-#elif defined(WIN32) + /* This uses Windows API instead of C runtime getenv() to get the environment + variable since some changes aren't always visible to the latter. #4774 */ +- char *buf = NULL; +- char *tmp; ++ TCHAR *buf = NULL; ++ TCHAR *tmp; + DWORD bufsize; + DWORD rc = 1; + const DWORD max = 32768; /* max env var size from MSCRT source */ + + for(;;) { +- tmp = realloc(buf, rc); ++ tmp = (TCHAR*)realloc(buf, rc * sizeof(TCHAR)); + if(!tmp) { + free(buf); + return NULL; +@@ -53,18 +50,42 @@ static char *GetEnv(const char *variable) + + /* It's possible for rc to be 0 if the variable was found but empty. + Since getenv doesn't make that distinction we ignore it as well. */ +- rc = GetEnvironmentVariableA(variable, buf, bufsize); ++ rc = GetEnvironmentVariable(variable, buf, bufsize); + if(!rc || rc == bufsize || rc > max) { + free(buf); + return NULL; + } + + /* if rc < bufsize then rc is bytes written not including null */ +- if(rc < bufsize) ++ if(rc < bufsize) { + return buf; +- ++ } + /* else rc is bytes needed, try again */ + } ++} ++#endif ++ ++static char *GetEnv(const char *variable) ++{ ++#if defined(_WIN32_WCE) || defined(CURL_WINDOWS_APP) ++ (void)variable; ++ return NULL; ++#elif defined(WIN32) ++#ifdef UNICODE ++ char *value = NULL; ++ wchar_t *variable_w = curlx_convert_UTF8_to_wchar(variable); ++ if(variable_w) { ++ wchar_t *value_w = GetEnvWin32(variable_w); ++ if(value_w) { ++ value = curlx_convert_wchar_to_UTF8(value_w); ++ free(value_w); ++ } ++ free(variable_w); ++ } ++ return value; ++#else ++ return GetEnvWin32(variable); ++#endif + #else + char *env = getenv(variable); + return (env && env[0])?strdup(env):NULL;