diff --git a/src/os.cpp b/src/os.cpp index 5844070609..6c1a2581df 100644 --- a/src/os.cpp +++ b/src/os.cpp @@ -1130,7 +1130,7 @@ Error os_get_cwd(Buf *out_cwd) { bool ATTRIBUTE_MUST_USE os_is_cygwin_pty(int fd) { #if defined(ZIG_OS_WINDOWS) HANDLE handle = (HANDLE)_get_osfhandle(fd); - + // Cygwin/msys's pty is a pipe. if (handle == INVALID_HANDLE_VALUE || GetFileType(handle) != FILE_TYPE_PIPE) { return false; @@ -1138,7 +1138,7 @@ bool ATTRIBUTE_MUST_USE os_is_cygwin_pty(int fd) { int size = sizeof(FILE_NAME_INFO) + sizeof(WCHAR) * MAX_PATH; WCHAR *p = NULL; - + FILE_NAME_INFO *nameinfo = (FILE_NAME_INFO *)allocate(size); if (nameinfo == NULL) { return false; @@ -1179,13 +1179,13 @@ bool ATTRIBUTE_MUST_USE os_is_cygwin_pty(int fd) { free(nameinfo); return (p != NULL); #else - return false + return false; #endif } bool os_stderr_tty(void) { #if defined(ZIG_OS_WINDOWS) - return _isatty(_fileno(stderr)) != 0 || os_is_cygwin_pty(_fileno(stderr)); + return _isatty(fileno(stderr)) != 0 || os_is_cygwin_pty(fileno(stderr)); #elif defined(ZIG_OS_POSIX) return isatty(STDERR_FILENO) != 0; #else diff --git a/src/os.hpp b/src/os.hpp index fc0e1929f2..7354528c34 100644 --- a/src/os.hpp +++ b/src/os.hpp @@ -89,6 +89,11 @@ struct Termination { #define OsFile int #endif +#if defined(ZIG_OS_WINDOWS) +#undef fileno +#define fileno _fileno +#endif + struct OsTimeStamp { uint64_t sec; uint64_t nsec; diff --git a/src/target.cpp b/src/target.cpp index d34254f1d1..695a810e39 100644 --- a/src/target.cpp +++ b/src/target.cpp @@ -1507,7 +1507,7 @@ bool target_is_single_threaded(const ZigTarget *target) { static ZigLLVM_EnvironmentType target_get_win32_abi() { FILE* files[] = { stdin, stdout, stderr, nullptr }; for (int i = 0; files[i] != nullptr; i++) { - if (os_is_cygwin_pty(_fileno(files[i]))) { + if (os_is_cygwin_pty(fileno(files[i]))) { return ZigLLVM_GNU; } } diff --git a/std/os/windows.zig b/std/os/windows.zig index ac76e8f58f..954e56443f 100644 --- a/std/os/windows.zig +++ b/std/os/windows.zig @@ -65,7 +65,7 @@ pub const CreateFileError = error{ InvalidUtf8, /// On Windows, file paths cannot contain these characters: - /// '/', '*', '?', '"', '<', '>', '|' + /// '*', '?', '"', '<', '>', '|', and '/' (when the ABI is not GNU) BadPathName, Unexpected, @@ -831,8 +831,8 @@ pub fn sliceToPrefixedSuffixedFileW(s: []const u8, comptime suffix: []const u16) // disallow forward slashes in zig std lib file functions on Windows. for (s) |byte| { switch (byte) { - '/', '*', '?', '"', '<', '>', '|' => return error.BadPathName, - else => {}, + '*', '?', '"', '<', '>', '|' => return error.BadPathName, + else => if (builtin.abi == .msvc and byte == '/') return error.BadPathName, } } const start_index = if (mem.startsWith(u8, s, "\\\\") or !std.fs.path.isAbsolute(s)) 0 else blk: { @@ -866,7 +866,6 @@ pub fn unexpectedError(err: DWORD) std.os.UnexpectedError { return error.Unexpected; } - /// Call this when you made a windows NtDll call /// and you get an unexpected status. pub fn unexpectedStatus(status: NTSTATUS) std.os.UnexpectedError {