1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-21 15:48:49 -05:00

made getenv() more threadsafe for win32

This commit is contained in:
Daniel Stenberg 2000-05-29 23:07:22 +00:00
parent 45885f30c2
commit 6d522c9c1d
5 changed files with 37 additions and 15 deletions

View File

@ -39,6 +39,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef WIN32
#include <windows.h>
@ -48,7 +49,7 @@ char *GetEnv(char *variable)
{
#ifdef WIN32
/* 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);
env[0] = '\0';
ExpandEnvironmentStrings(temp, env, sizeof(env));
@ -56,7 +57,7 @@ char *GetEnv(char *variable)
/* no length control */
char *env = getenv(variable);
#endif
return env;
return env?strdup(env):NULL;
}
char *curl_GetEnv(char *v)

View File

@ -95,9 +95,14 @@ int ParseNetrc(char *host,
#define NETRC DOT_CHAR "netrc"
if(!home || (strlen(home)>(sizeof(netrcbuffer)-strlen(NETRC))))
if(!home)
return -1;
if(strlen(home)>(sizeof(netrcbuffer)-strlen(NETRC))) {
free(home);
return -1;
}
sprintf(netrcbuffer, "%s%s%s", home, DIR_CHAR, NETRC);
file = fopen(netrcbuffer, "r");
@ -162,6 +167,8 @@ int ParseNetrc(char *host,
fclose(file);
}
free(home);
return retcode;
}

View File

@ -387,6 +387,7 @@ void ProgressInit(struct UrlData *data, int max/*, int options, int moremax*/)
/* 20000318 mgs */
int scr_size [2];
#endif
char *colp;
if(data->conf&(CONF_NOPROGRESS|CONF_MUTE))
return;
@ -399,8 +400,11 @@ void ProgressInit(struct UrlData *data, int max/*, int options, int moremax*/)
/* 20000318 mgs
* 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 */
if (curl_GetEnv("COLUMNS") != NULL)
width = atoi(curl_GetEnv("COLUMNS"));
colp = curl_GetEnv("COLUMNS");
if (colp != NULL) {
width = atoi(colp);
free(colp);
}
else
width = 79;
#else

View File

@ -172,6 +172,12 @@ void urlfree(struct UrlData *data, bool totally)
data->firstsocket=-1;
}
if(data->bits.proxystringalloc) {
data->bits.proxystringalloc=0;
free(data->proxy);
data->proxy=NULL;
}
if(data->ptr_proxyuserpwd) {
free(data->ptr_proxyuserpwd);
@ -815,10 +821,13 @@ CURLcode curl_connect(CURL *curl, CURLconnect **in_connect)
if(proxy && *proxy) {
/* we have a proxy here to set */
data->proxy = proxy;
data->bits.proxystringalloc=1; /* this needs to be freed later */
data->bits.httpproxy=1;
}
} /* if (!nope) - it wasn't specfied non-proxy */
} /* NO_PROXY wasn't specified or '*' */
if(no_proxy)
free(no_proxy);
} /* if not using proxy */
if((conn->protocol&PROT_MISSING) && data->bits.httpproxy ) {

View File

@ -240,26 +240,27 @@ struct FTP {
struct Configbits {
bool ftp_append;
bool ftp_ascii;
bool http_post;
bool http_set_referer;
bool ftp_list_only;
bool ftp_use_port;
bool hide_progress;
bool http_fail_on_error;
bool http_follow_location;
bool http_formpost;
bool http_include_header;
bool http_follow_location;
bool http_post;
bool http_put;
bool http_set_referer;
bool httpproxy;
bool mute;
bool no_body;
bool ftp_list_only;
bool use_netrc;
bool ftp_use_port;
bool proxy_user_passwd;
bool proxystringalloc; /* the http proxy string is malloc()'ed */
bool set_port;
bool set_range;
bool mute;
bool hide_progress;
bool upload;
bool use_netrc;
bool user_passwd;
bool proxy_user_passwd;
bool verbose;
bool httpproxy;
};
typedef size_t (*progress_callback)(void *clientp,