From 9f5c0b6e6049fa53807be3334ce7ce96de2d24b4 Mon Sep 17 00:00:00 2001
From: Andrew Kelley
Date: Fri, 19 Jan 2018 16:30:50 -0500
Subject: windows-compatible os_rename function
windows libc rename() requires destination file path to not exist
---
src/os.cpp | 11 +++++++++++
1 file changed, 11 insertions(+)
(limited to 'src/os.cpp')
diff --git a/src/os.cpp b/src/os.cpp
index ef12464c8c..48512a273d 100644
--- 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;
--
cgit v1.2.3
From 890bf001dbd4120ca8660d0e63594aa27d2a683f Mon Sep 17 00:00:00 2001
From: Andrew Kelley
Date: Fri, 19 Jan 2018 16:53:08 -0500
Subject: os_rename uses MoveFileEx on windows
---
src/os.cpp | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)
(limited to 'src/os.cpp')
diff --git a/src/os.cpp b/src/os.cpp
index 48512a273d..4667554b04 100644
--- a/src/os.cpp
+++ b/src/os.cpp
@@ -797,17 +797,15 @@ int os_rename(Buf *src_path, Buf *dest_path) {
if (buf_eql_buf(src_path, dest_path)) {
return 0;
}
+#if defined(ZIG_OS_WINDOWS)
+ if (!MoveFileEx(buf_ptr(dest_path), buf_ptr(src_path), MOVEFILE_REPLACE_EXISTING)) {
+ return ErrorFileSystem;
+ }
+#else
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;
}
+#endif
return 0;
}
--
cgit v1.2.3
From ddd04a7b46f897314c8c1c540c998f90fea64ba2 Mon Sep 17 00:00:00 2001
From: Andrew Kelley
Date: Fri, 19 Jan 2018 22:17:31 -0500
Subject: fix docgen on windows
---
doc/langref.html.in | 12 ++++++++----
src/os.cpp | 4 +---
2 files changed, 9 insertions(+), 7 deletions(-)
(limited to 'src/os.cpp')
diff --git a/doc/langref.html.in b/doc/langref.html.in
index 40815f5d1a..db7d760e98 100644
--- a/doc/langref.html.in
+++ b/doc/langref.html.in
@@ -2099,10 +2099,10 @@ const os_msg = switch (builtin.os) {
// evaluated if the target expression is compile-time known.
test "switch inside function" {
switch (builtin.os) {
- builtin.Os.windows => {
- // On an OS other than windows, block is not even analyzed,
+ builtin.Os.fuchsia => {
+ // On an OS other than fuchsia, block is not even analyzed,
// so this compile error is not triggered.
- // On windows this compile error would be triggered.
+ // On fuchsia this compile error would be triggered.
@compileError("windows not supported");
},
else => {},
@@ -5172,7 +5172,11 @@ pub fn main() {
{#code_begin|exe#}
{#link_libc#}
-const c = @cImport(@cInclude("stdio.h"));
+const c = @cImport({
+ // See https://github.com/zig-lang/zig/issues/515
+ @cDefine("_NO_CRT_STDIO_INLINE", "1");
+ @cInclude("stdio.h");
+});
pub fn main() {
_ = c.printf(c"hello\n");
}
diff --git a/src/os.cpp b/src/os.cpp
index 4667554b04..8f830b94c9 100644
--- a/src/os.cpp
+++ b/src/os.cpp
@@ -390,7 +390,6 @@ static int os_exec_process_posix(const char *exe, ZigList &args,
#if defined(ZIG_OS_WINDOWS)
-/*
static void win32_panic(const char *str) {
DWORD err = GetLastError();
LPSTR messageBuffer = nullptr;
@@ -400,7 +399,6 @@ static void win32_panic(const char *str) {
zig_panic(str, messageBuffer);
LocalFree(messageBuffer);
}
-*/
static int os_exec_process_windows(const char *exe, ZigList &args,
Termination *term, Buf *out_stderr, Buf *out_stdout)
@@ -798,7 +796,7 @@ int os_rename(Buf *src_path, Buf *dest_path) {
return 0;
}
#if defined(ZIG_OS_WINDOWS)
- if (!MoveFileEx(buf_ptr(dest_path), buf_ptr(src_path), MOVEFILE_REPLACE_EXISTING)) {
+ if (!MoveFileExA(buf_ptr(src_path), buf_ptr(dest_path), MOVEFILE_REPLACE_EXISTING)) {
return ErrorFileSystem;
}
#else
--
cgit v1.2.3
From 517e8ea4269fb832f29d9eab642d57f1a8371149 Mon Sep 17 00:00:00 2001
From: Andrew Kelley
Date: Sat, 20 Jan 2018 02:49:53 -0500
Subject: remove unused function, fixes mingw build
---
src/os.cpp | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
(limited to 'src/os.cpp')
diff --git a/src/os.cpp b/src/os.cpp
index 8f830b94c9..e312854612 100644
--- a/src/os.cpp
+++ b/src/os.cpp
@@ -390,15 +390,15 @@ static int os_exec_process_posix(const char *exe, ZigList &args,
#if defined(ZIG_OS_WINDOWS)
-static void win32_panic(const char *str) {
- DWORD err = GetLastError();
- LPSTR messageBuffer = nullptr;
- FormatMessageA(
- FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
- NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&messageBuffer, 0, NULL);
- zig_panic(str, messageBuffer);
- LocalFree(messageBuffer);
-}
+//static void win32_panic(const char *str) {
+// DWORD err = GetLastError();
+// LPSTR messageBuffer = nullptr;
+// FormatMessageA(
+// FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
+// NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&messageBuffer, 0, NULL);
+// zig_panic(str, messageBuffer);
+// LocalFree(messageBuffer);
+//}
static int os_exec_process_windows(const char *exe, ZigList &args,
Termination *term, Buf *out_stderr, Buf *out_stdout)
--
cgit v1.2.3