From 90dddeb4cc90093ab42687bbda7cd7a5428355c2 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Sun, 16 Feb 2014 13:25:02 -0800 Subject: Rename old 'xml' file as 'bak' file when saving If you use the standard naming convention and end your subsurface filename in ".xml", we will now save away any previous xml file as a "bak" file before writing a new one. This can be useful for: - recovering from mistakes that deleted old dives - seeing what changed (ie you can do things like "diff -u xyz.bak xyz.xml") after doing some operation and saving the result. However, this does only a single level of backups - if you save twice, you will obviously have lost the original. I'd strongly encourage some external backup system in addition to this very simplistic backup. Signed-off-by: Linus Torvalds Signed-off-by: Dirk Hohndel --- windows.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'windows.c') diff --git a/windows.c b/windows.c index 7c537f6e5..042e1c619 100644 --- a/windows.c +++ b/windows.c @@ -111,6 +111,22 @@ static wchar_t *utf8_to_utf16_fl(const char *utf8, char *file, int line) /* bellow we provide a set of wrappers for some I/O functions to use wchar_t. * on win32 this solves the issue that we need paths to be utf-16 encoded. */ +int subsurface_rename(const char *path, const char *newpath) +{ + int ret = -1; + if (!path || !newpath) + return -1; + + wchar_t *wpath = utf8_to_utf16(path); + wchar_t *wnewpath = utf8_to_utf16(newpath); + + if (wpath && wnewpath) + ret = _wrename(wpath, wnewpath); + free((void *)wpath); + free((void *)wnewpath); + return ret; +} + int subsurface_open(const char *path, int oflags, mode_t mode) { int ret = -1; -- cgit v1.2.3-70-g09d2