authorgravatar for emekankurumeh@outlook.comemekoi <emekankurumeh@outlook.com> 2019-08-01 18:27:39-05:00
committergravatar for emekankurumeh@outlook.comemekoi <emekankurumeh@outlook.com> 2019-08-02 19:39:33-05:00
log102d3f30c406e2818c6320a48f2405fa7e1e4237
tree975dd34f14528cff0bd57fa2fc8e08479a11ccff
parentf15ec9a59b777a2b7998518858f11f5da0dfcb2d

accept unix style paths on windows-gnu


4 files changed, 13 insertions(+), 9 deletions(-)

src/os.cpp+4-4
...@@ -1130,7 +1130,7 @@ Error os_get_cwd(Buf *out_cwd) {...@@ -1130,7 +1130,7 @@ Error os_get_cwd(Buf *out_cwd) {
1130bool ATTRIBUTE_MUST_USE os_is_cygwin_pty(int fd) {1130bool ATTRIBUTE_MUST_USE os_is_cygwin_pty(int fd) {
1131#if defined(ZIG_OS_WINDOWS)1131#if defined(ZIG_OS_WINDOWS)
1132 HANDLE handle = (HANDLE)_get_osfhandle(fd);1132 HANDLE handle = (HANDLE)_get_osfhandle(fd);
1133 1133
1134 // Cygwin/msys's pty is a pipe.1134 // Cygwin/msys's pty is a pipe.
1135 if (handle == INVALID_HANDLE_VALUE || GetFileType(handle) != FILE_TYPE_PIPE) {1135 if (handle == INVALID_HANDLE_VALUE || GetFileType(handle) != FILE_TYPE_PIPE) {
1136 return false;1136 return false;
...@@ -1138,7 +1138,7 @@ bool ATTRIBUTE_MUST_USE os_is_cygwin_pty(int fd) {...@@ -1138,7 +1138,7 @@ bool ATTRIBUTE_MUST_USE os_is_cygwin_pty(int fd) {
11381138
1139 int size = sizeof(FILE_NAME_INFO) + sizeof(WCHAR) * MAX_PATH;1139 int size = sizeof(FILE_NAME_INFO) + sizeof(WCHAR) * MAX_PATH;
1140 WCHAR *p = NULL;1140 WCHAR *p = NULL;
1141 1141
1142 FILE_NAME_INFO *nameinfo = (FILE_NAME_INFO *)allocate<char>(size);1142 FILE_NAME_INFO *nameinfo = (FILE_NAME_INFO *)allocate<char>(size);
1143 if (nameinfo == NULL) {1143 if (nameinfo == NULL) {
1144 return false;1144 return false;
...@@ -1179,13 +1179,13 @@ bool ATTRIBUTE_MUST_USE os_is_cygwin_pty(int fd) {...@@ -1179,13 +1179,13 @@ bool ATTRIBUTE_MUST_USE os_is_cygwin_pty(int fd) {
1179 free(nameinfo);1179 free(nameinfo);
1180 return (p != NULL);1180 return (p != NULL);
1181#else1181#else
1182 return false1182 return false;
1183#endif1183#endif
1184}1184}
11851185
1186bool os_stderr_tty(void) {1186bool os_stderr_tty(void) {
1187#if defined(ZIG_OS_WINDOWS)1187#if defined(ZIG_OS_WINDOWS)
1188 return _isatty(_fileno(stderr)) != 0 || os_is_cygwin_pty(_fileno(stderr));1188 return _isatty(fileno(stderr)) != 0 || os_is_cygwin_pty(fileno(stderr));
1189#elif defined(ZIG_OS_POSIX)1189#elif defined(ZIG_OS_POSIX)
1190 return isatty(STDERR_FILENO) != 0;1190 return isatty(STDERR_FILENO) != 0;
1191#else1191#else
src/os.hpp+5
...@@ -89,6 +89,11 @@ struct Termination {...@@ -89,6 +89,11 @@ struct Termination {
89#define OsFile int89#define OsFile int
90#endif90#endif
9191
92#if defined(ZIG_OS_WINDOWS)
93#undef fileno
94#define fileno _fileno
95#endif
96
92struct OsTimeStamp {97struct OsTimeStamp {
93 uint64_t sec;98 uint64_t sec;
94 uint64_t nsec;99 uint64_t nsec;
src/target.cpp+1-1
...@@ -1507,7 +1507,7 @@ bool target_is_single_threaded(const ZigTarget *target) {...@@ -1507,7 +1507,7 @@ bool target_is_single_threaded(const ZigTarget *target) {
1507static ZigLLVM_EnvironmentType target_get_win32_abi() {1507static ZigLLVM_EnvironmentType target_get_win32_abi() {
1508 FILE* files[] = { stdin, stdout, stderr, nullptr };1508 FILE* files[] = { stdin, stdout, stderr, nullptr };
1509 for (int i = 0; files[i] != nullptr; i++) {1509 for (int i = 0; files[i] != nullptr; i++) {
1510 if (os_is_cygwin_pty(_fileno(files[i]))) {1510 if (os_is_cygwin_pty(fileno(files[i]))) {
1511 return ZigLLVM_GNU;1511 return ZigLLVM_GNU;
1512 }1512 }
1513 }1513 }
std/os/windows.zig+3-4
...@@ -65,7 +65,7 @@ pub const CreateFileError = error{...@@ -65,7 +65,7 @@ pub const CreateFileError = error{
65 InvalidUtf8,65 InvalidUtf8,
6666
67 /// On Windows, file paths cannot contain these characters:67 /// On Windows, file paths cannot contain these characters:
68 /// '/', '*', '?', '"', '<', '>', '|'68 /// '*', '?', '"', '<', '>', '|', and '/' (when the ABI is not GNU)
69 BadPathName,69 BadPathName,
7070
71 Unexpected,71 Unexpected,
...@@ -831,8 +831,8 @@ pub fn sliceToPrefixedSuffixedFileW(s: []const u8, comptime suffix: []const u16)...@@ -831,8 +831,8 @@ pub fn sliceToPrefixedSuffixedFileW(s: []const u8, comptime suffix: []const u16)
831 // disallow forward slashes in zig std lib file functions on Windows.831 // disallow forward slashes in zig std lib file functions on Windows.
832 for (s) |byte| {832 for (s) |byte| {
833 switch (byte) {833 switch (byte) {
834 '/', '*', '?', '"', '<', '>', '|' => return error.BadPathName,834 '*', '?', '"', '<', '>', '|' => return error.BadPathName,
835 else => {},835 else => if (builtin.abi == .msvc and byte == '/') return error.BadPathName,
836 }836 }
837 }837 }
838 const start_index = if (mem.startsWith(u8, s, "\\\\") or !std.fs.path.isAbsolute(s)) 0 else blk: {838 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 {...@@ -866,7 +866,6 @@ pub fn unexpectedError(err: DWORD) std.os.UnexpectedError {
866 return error.Unexpected;866 return error.Unexpected;
867}867}
868868
869
870/// Call this when you made a windows NtDll call869/// Call this when you made a windows NtDll call
871/// and you get an unexpected status.870/// and you get an unexpected status.
872pub fn unexpectedStatus(status: NTSTATUS) std.os.UnexpectedError {871pub fn unexpectedStatus(status: NTSTATUS) std.os.UnexpectedError {