From 330f133224af18c65b9325d9b6502e07b4f09f6b Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 17 Feb 2020 22:55:34 +0100 Subject: rename: a new file for Curl_rename() And make the cookie save function use it. --- lib/cookie.c | 28 ++-------------------------- 1 file changed, 2 insertions(+), 26 deletions(-) (limited to 'lib/cookie.c') diff --git a/lib/cookie.c b/lib/cookie.c index 7ae90ea27..2dfdc733f 100644 --- a/lib/cookie.c +++ b/lib/cookie.c @@ -98,6 +98,7 @@ Example set of cookies: #include "inet_pton.h" #include "parsedate.h" #include "rand.h" +#include "rename.h" /* The last 3 #include files should be in this order */ #include "curl_printf.h" @@ -1494,31 +1495,6 @@ static char *get_netscape_format(const struct Cookie *co) co->value?co->value:""); } -/* return 0 on success, 1 on error */ -static int xrename(const char *oldpath, const char *newpath) -{ -#ifdef WIN32 - /* rename() on Windows doesn't overwrite, so we can't use it here. - MoveFileExA() will overwrite and is usually atomic, however it fails - when there are open handles to the file. */ - const int max_wait_ms = 1000; - struct curltime start = Curl_now(); - for(;;) { - timediff_t diff; - if(MoveFileExA(oldpath, newpath, MOVEFILE_REPLACE_EXISTING)) - break; - diff = Curl_timediff(Curl_now(), start); - if(diff < 0 || diff > max_wait_ms) - return 1; - Sleep(1); - } -#else - if(rename(oldpath, newpath)) - return 1; -#endif - return 0; -} - /* * cookie_output() * @@ -1606,7 +1582,7 @@ static int cookie_output(struct Curl_easy *data, if(out && !use_stdout) { fclose(out); out = NULL; - if(xrename(tempstore, filename)) { + if(Curl_rename(tempstore, filename)) { unlink(tempstore); goto error; } -- cgit v1.2.3