blob: 4226a3b37d05269bf60402f818727b3a070fb318 [file] [log] [blame]
From 5452f0ed02bfbca5bb7cc68336a87844246c55da Mon Sep 17 00:00:00 2001
From: JohnD <john.donoghue@ieee.org>
Date: Thu, 4 Apr 2019 10:58:13 -0400
Subject: [PATCH] Add private history_rename function and in WIN32, use windows
function instead of rename
---
histfile.c | 26 ++++++++++++++++++++++----
1 file changed, 22 insertions(+), 4 deletions(-)
diff --git a/histfile.c b/histfile.c
index dc64bde..cf23f53 100644
--- a/histfile.c
+++ b/histfile.c
@@ -107,6 +107,11 @@ extern int errno;
# define PATH_MAX 1024 /* default */
#endif
+#if defined(_WIN32)
+ #define WIN32_LEAN_AND_MEAN
+ #include <windows.h>
+#endif
+
extern void _hs_append_history_line PARAMS((int, const char *));
/* history file version; currently unused */
@@ -139,6 +144,19 @@ static char *history_tempfile PARAMS((const char *));
static int histfile_backup PARAMS((const char *, const char *));
static int histfile_restore PARAMS((const char *, const char *));
+static int
+history_rename(const char *from, const char *to)
+{
+#if defined(_WIN32)
+ if (!MoveFileEx(from, to, MOVEFILE_REPLACE_EXISTING)) {
+ return -1;
+ }
+ return 0;
+#else
+ return rename(from, to);
+#endif
+}
+
/* Return the string that should be used in the place of this
filename. This only matters when you don't specify the
filename to read_history (), or write_history (). */
@@ -448,10 +466,10 @@ histfile_backup (const char *filename, const char *back)
if ((n = readlink (filename, linkbuf, sizeof (linkbuf) - 1)) > 0)
{
linkbuf[n] = '\0';
- return (rename (linkbuf, back));
+ return (history_rename (linkbuf, back));
}
#endif
- return (rename (filename, back));
+ return (history_rename (filename, back));
}
/* Restore ORIG from BACKUP handling case where ORIG is a symlink
@@ -467,10 +485,10 @@ histfile_restore (const char *backup, const char *orig)
if ((n = readlink (orig, linkbuf, sizeof (linkbuf) - 1)) > 0)
{
linkbuf[n] = '\0';
- return (rename (backup, linkbuf));
+ return (history_rename (backup, linkbuf));
}
#endif
- return (rename (backup, orig));
+ return (history_rename (backup, orig));
}
/* Truncate the history file FNAME, leaving only LINES trailing lines.
--
2.17.1