summaryrefslogtreecommitdiff
path: root/lib/cookie.c
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2020-02-17 22:55:34 +0100
committerDaniel Stenberg <daniel@haxx.se>2020-02-18 07:49:15 +0100
commit330f133224af18c65b9325d9b6502e07b4f09f6b (patch)
tree7e68b7bbfb84fc9b1cb7f280bbe142cc1cf1592c /lib/cookie.c
parentb834890a3fa3f525cd8ef4e99554cdb4558d7e1b (diff)
downloadcurl-330f133224af18c65b9325d9b6502e07b4f09f6b.tar.gz
rename: a new file for Curl_rename()
And make the cookie save function use it.
Diffstat (limited to 'lib/cookie.c')
-rw-r--r--lib/cookie.c28
1 files changed, 2 insertions, 26 deletions
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;
}