diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2020-02-16 22:34:40 -0500 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2020-02-16 22:34:40 -0500 |
| commit | d5860cbade79141c4c547a3411befb8448dd56ab (patch) | |
| tree | 5b1d792ae3fcade10525182e3d6557905f30deeb /src/os.cpp | |
| parent | 364a284eb3b5e90a9ec0ea6b29be8b74d2a92fa5 (diff) | |
| download | zig-d5860cbade79141c4c547a3411befb8448dd56ab.tar.gz zig-d5860cbade79141c4c547a3411befb8448dd56ab.zip | |
fix os_update_file implementation on Windows
Diffstat (limited to 'src/os.cpp')
| -rw-r--r-- | src/os.cpp | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/src/os.cpp b/src/os.cpp index 65e1b79524..48bf78e1cb 100644 --- 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); |
