diff options
Diffstat (limited to 'lib/cookie.c')
-rw-r--r-- | lib/cookie.c | 39 |
1 files changed, 9 insertions, 30 deletions
diff --git a/lib/cookie.c b/lib/cookie.c index 8831b2a0e..2183d5a19 100644 --- a/lib/cookie.c +++ b/lib/cookie.c @@ -83,7 +83,6 @@ Example set of cookies: #include "curl_setup.h" #if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES) - #include "urldata.h" #include "cookie.h" #include "psl.h" @@ -97,8 +96,7 @@ Example set of cookies: #include "curl_memrchr.h" #include "inet_pton.h" #include "parsedate.h" -#include "rand.h" -#include "rename.h" +#include "openlock.h" /* The last 3 #include files should be in this order */ #include "curl_printf.h" @@ -1515,14 +1513,13 @@ static char *get_netscape_format(const struct Cookie *co) * * The function returns non-zero on write failure. */ -static int cookie_output(struct Curl_easy *data, - struct CookieInfo *c, const char *filename) +static int cookie_output(struct CookieInfo *c, const char *filename) { struct Cookie *co; FILE *out = NULL; bool use_stdout = FALSE; - char *tempstore = NULL; bool error = false; + struct openlock o; if(!c) /* no cookie engine alive */ @@ -1537,18 +1534,10 @@ static int cookie_output(struct Curl_easy *data, use_stdout = TRUE; } else { - unsigned char randsuffix[9]; - - if(Curl_rand_hex(data, randsuffix, sizeof(randsuffix))) - return 2; - - tempstore = aprintf("%s.%s.tmp", filename, randsuffix); - if(!tempstore) - return 1; - - out = fopen(tempstore, FOPEN_WRITETEXT); - if(!out) + CURLcode result = Curl_openlock(filename, &o); + if(result) goto error; + out = o.out; } fputs("# Netscape HTTP Cookie File\n" @@ -1591,22 +1580,12 @@ static int cookie_output(struct Curl_easy *data, free(array); } - if(!use_stdout) { - fclose(out); - out = NULL; - if(Curl_rename(tempstore, filename)) { - unlink(tempstore); - goto error; - } - } - goto cleanup; error: error = true; cleanup: - if(out && !use_stdout) - fclose(out); - free(tempstore); + if(!use_stdout) + Curl_openunlock(&o); return error ? 1 : 0; } @@ -1665,7 +1644,7 @@ void Curl_flush_cookies(struct Curl_easy *data, bool cleanup) Curl_share_lock(data, CURL_LOCK_DATA_COOKIE, CURL_LOCK_ACCESS_SINGLE); /* if we have a destination file for all the cookies to get dumped to */ - if(cookie_output(data, data->cookies, data->set.str[STRING_COOKIEJAR])) + if(cookie_output(data->cookies, data->set.str[STRING_COOKIEJAR])) infof(data, "WARNING: failed to save cookies in %s\n", data->set.str[STRING_COOKIEJAR]); } |