zig

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

commit d5860cbade79141c4c547a3411befb8448dd56ab (tree)
parent 364a284eb3b5e90a9ec0ea6b29be8b74d2a92fa5
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Sun, 16 Feb 2020 22:34:40 -0500

fix os_update_file implementation on Windows

Diffstat:
Msrc/os.cpp | 27++++++++++++++++++++-------
1 file changed, 20 insertions(+), 7 deletions(-)

diff --git a/src/os.cpp b/src/os.cpp @@ -1070,9 +1070,11 @@ static FILETIME windows_os_timestamp_to_filetime(OsTimeStamp mtime) { static Error set_file_times(OsFile file, OsTimeStamp ts) { #if defined(ZIG_OS_WINDOWS) - const atime_ft = windows.nanoSecondsToFileTime(atime); - const mtime_ft = windows.nanoSecondsToFileTime(mtime); - return SetFileTime(file, null, &atime_ft, &mtime_ft); + FILETIME ft = windows_os_timestamp_to_filetime(ts); + if (SetFileTime(file, nullptr, &ft, &ft) == 0) { + return ErrorUnexpected; + } + return ErrorNone; #else struct timespec times[2] = { { ts.sec, ts.nsec }, @@ -1114,14 +1116,25 @@ Error os_update_file(Buf *src_path, Buf *dst_path) { os_file_close(&dst_file); return ErrorNone; } - +#if defined(ZIG_OS_WINDOWS) + if (SetEndOfFile(dst_file) == 0) { + return ErrorUnexpected; + } +#else + if (ftruncate(dst_file, 0) == -1) { + return ErrorUnexpected; + } +#endif +#if defined(ZIG_OS_WINDOWS) + FILE *src_libc_file = _fdopen(_open_osfhandle((intptr_t)src_file, _O_RDONLY), "rb"); + FILE *dst_libc_file = _fdopen(_open_osfhandle((intptr_t)dst_file, 0), "wb"); +#else FILE *src_libc_file = fdopen(src_file, "rb"); FILE *dst_libc_file = fdopen(dst_file, "wb"); +#endif assert(src_libc_file); assert(dst_libc_file); - if (ftruncate(dst_file, 0) == -1) { - return ErrorUnexpected; - } + if ((err = copy_open_files(src_libc_file, dst_libc_file))) { fclose(src_libc_file); fclose(dst_libc_file);