zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 9f5c0b6e6049fa53807be3334ce7ce96de2d24b4 (tree)
parent 2eede35577fdd917e5680a2bf3c2cf64ff9339f2
Author: Andrew Kelley <superjoe30@gmail.com>
Date:   Fri, 19 Jan 2018 16:30:50 -0500

windows-compatible os_rename function

windows libc rename() requires destination file path to not exist

Diffstat:
Msrc/os.cpp | 11+++++++++++
1 file changed, 11 insertions(+), 0 deletions(-)

diff --git a/src/os.cpp b/src/os.cpp @@ -794,7 +794,18 @@ int os_delete_file(Buf *path) { } int os_rename(Buf *src_path, Buf *dest_path) { + if (buf_eql_buf(src_path, dest_path)) { + return 0; + } if (rename(buf_ptr(src_path), buf_ptr(dest_path)) == -1) { + // Windows requires the dest path to be missing + if (errno == EACCES) { + remove(buf_ptr(dest_path)); + if (rename(buf_ptr(src_path), buf_ptr(dest_path)) == -1) { + return ErrorFileSystem; + } + return 0; + } return ErrorFileSystem; } return 0;