mirror of
https://github.com/moparisthebest/curl
synced 2024-12-21 23:58:49 -05:00
made getenv() more threadsafe for win32
This commit is contained in:
parent
45885f30c2
commit
6d522c9c1d
@ -39,6 +39,7 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
@ -48,7 +49,7 @@ char *GetEnv(char *variable)
|
|||||||
{
|
{
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
/* This shit requires windows.h (HUGE) to be included */
|
/* This shit requires windows.h (HUGE) to be included */
|
||||||
static char env[MAX_PATH]; /* MAX_PATH is from windef.h */
|
char env[MAX_PATH]; /* MAX_PATH is from windef.h */
|
||||||
char *temp = getenv(variable);
|
char *temp = getenv(variable);
|
||||||
env[0] = '\0';
|
env[0] = '\0';
|
||||||
ExpandEnvironmentStrings(temp, env, sizeof(env));
|
ExpandEnvironmentStrings(temp, env, sizeof(env));
|
||||||
@ -56,7 +57,7 @@ char *GetEnv(char *variable)
|
|||||||
/* no length control */
|
/* no length control */
|
||||||
char *env = getenv(variable);
|
char *env = getenv(variable);
|
||||||
#endif
|
#endif
|
||||||
return env;
|
return env?strdup(env):NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *curl_GetEnv(char *v)
|
char *curl_GetEnv(char *v)
|
||||||
|
@ -95,9 +95,14 @@ int ParseNetrc(char *host,
|
|||||||
|
|
||||||
#define NETRC DOT_CHAR "netrc"
|
#define NETRC DOT_CHAR "netrc"
|
||||||
|
|
||||||
if(!home || (strlen(home)>(sizeof(netrcbuffer)-strlen(NETRC))))
|
if(!home)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
if(strlen(home)>(sizeof(netrcbuffer)-strlen(NETRC))) {
|
||||||
|
free(home);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
sprintf(netrcbuffer, "%s%s%s", home, DIR_CHAR, NETRC);
|
sprintf(netrcbuffer, "%s%s%s", home, DIR_CHAR, NETRC);
|
||||||
|
|
||||||
file = fopen(netrcbuffer, "r");
|
file = fopen(netrcbuffer, "r");
|
||||||
@ -162,6 +167,8 @@ int ParseNetrc(char *host,
|
|||||||
fclose(file);
|
fclose(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free(home);
|
||||||
|
|
||||||
return retcode;
|
return retcode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -387,6 +387,7 @@ void ProgressInit(struct UrlData *data, int max/*, int options, int moremax*/)
|
|||||||
/* 20000318 mgs */
|
/* 20000318 mgs */
|
||||||
int scr_size [2];
|
int scr_size [2];
|
||||||
#endif
|
#endif
|
||||||
|
char *colp;
|
||||||
|
|
||||||
if(data->conf&(CONF_NOPROGRESS|CONF_MUTE))
|
if(data->conf&(CONF_NOPROGRESS|CONF_MUTE))
|
||||||
return;
|
return;
|
||||||
@ -399,8 +400,11 @@ void ProgressInit(struct UrlData *data, int max/*, int options, int moremax*/)
|
|||||||
/* 20000318 mgs
|
/* 20000318 mgs
|
||||||
* OS/2 users most likely won't have this env var set, and besides that
|
* OS/2 users most likely won't have this env var set, and besides that
|
||||||
* we're using our own way to determine screen width */
|
* we're using our own way to determine screen width */
|
||||||
if (curl_GetEnv("COLUMNS") != NULL)
|
colp = curl_GetEnv("COLUMNS");
|
||||||
width = atoi(curl_GetEnv("COLUMNS"));
|
if (colp != NULL) {
|
||||||
|
width = atoi(colp);
|
||||||
|
free(colp);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
width = 79;
|
width = 79;
|
||||||
#else
|
#else
|
||||||
|
@ -172,6 +172,12 @@ void urlfree(struct UrlData *data, bool totally)
|
|||||||
data->firstsocket=-1;
|
data->firstsocket=-1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(data->bits.proxystringalloc) {
|
||||||
|
data->bits.proxystringalloc=0;
|
||||||
|
free(data->proxy);
|
||||||
|
data->proxy=NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if(data->ptr_proxyuserpwd) {
|
if(data->ptr_proxyuserpwd) {
|
||||||
free(data->ptr_proxyuserpwd);
|
free(data->ptr_proxyuserpwd);
|
||||||
@ -815,10 +821,13 @@ CURLcode curl_connect(CURL *curl, CURLconnect **in_connect)
|
|||||||
if(proxy && *proxy) {
|
if(proxy && *proxy) {
|
||||||
/* we have a proxy here to set */
|
/* we have a proxy here to set */
|
||||||
data->proxy = proxy;
|
data->proxy = proxy;
|
||||||
|
data->bits.proxystringalloc=1; /* this needs to be freed later */
|
||||||
data->bits.httpproxy=1;
|
data->bits.httpproxy=1;
|
||||||
}
|
}
|
||||||
} /* if (!nope) - it wasn't specfied non-proxy */
|
} /* if (!nope) - it wasn't specfied non-proxy */
|
||||||
} /* NO_PROXY wasn't specified or '*' */
|
} /* NO_PROXY wasn't specified or '*' */
|
||||||
|
if(no_proxy)
|
||||||
|
free(no_proxy);
|
||||||
} /* if not using proxy */
|
} /* if not using proxy */
|
||||||
|
|
||||||
if((conn->protocol&PROT_MISSING) && data->bits.httpproxy ) {
|
if((conn->protocol&PROT_MISSING) && data->bits.httpproxy ) {
|
||||||
|
@ -240,26 +240,27 @@ struct FTP {
|
|||||||
struct Configbits {
|
struct Configbits {
|
||||||
bool ftp_append;
|
bool ftp_append;
|
||||||
bool ftp_ascii;
|
bool ftp_ascii;
|
||||||
bool http_post;
|
bool ftp_list_only;
|
||||||
bool http_set_referer;
|
bool ftp_use_port;
|
||||||
|
bool hide_progress;
|
||||||
bool http_fail_on_error;
|
bool http_fail_on_error;
|
||||||
|
bool http_follow_location;
|
||||||
bool http_formpost;
|
bool http_formpost;
|
||||||
bool http_include_header;
|
bool http_include_header;
|
||||||
bool http_follow_location;
|
bool http_post;
|
||||||
bool http_put;
|
bool http_put;
|
||||||
|
bool http_set_referer;
|
||||||
|
bool httpproxy;
|
||||||
|
bool mute;
|
||||||
bool no_body;
|
bool no_body;
|
||||||
bool ftp_list_only;
|
bool proxy_user_passwd;
|
||||||
bool use_netrc;
|
bool proxystringalloc; /* the http proxy string is malloc()'ed */
|
||||||
bool ftp_use_port;
|
|
||||||
bool set_port;
|
bool set_port;
|
||||||
bool set_range;
|
bool set_range;
|
||||||
bool mute;
|
|
||||||
bool hide_progress;
|
|
||||||
bool upload;
|
bool upload;
|
||||||
|
bool use_netrc;
|
||||||
bool user_passwd;
|
bool user_passwd;
|
||||||
bool proxy_user_passwd;
|
|
||||||
bool verbose;
|
bool verbose;
|
||||||
bool httpproxy;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef size_t (*progress_callback)(void *clientp,
|
typedef size_t (*progress_callback)(void *clientp,
|
||||||
|
Loading…
Reference in New Issue
Block a user