authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-05-27 15:54:45-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-05-27 15:55:15-04:00
logaf4b8eb6c087618729c821269e9f6d662d5f193c
treeccc371a4d9e27ac4afe06fc58b2befc7a4d65a44
parent86bb7e5984c248f37aaa465c7acb0bf97c13b39e

windows does not integrate cleanly with libc


2 files changed, 25 insertions(+), 25 deletions(-)

std/os.zig+24-24
...@@ -718,7 +718,7 @@ pub const GetCwdError = error{...@@ -718,7 +718,7 @@ pub const GetCwdError = error{
718718
719/// The result is a slice of out_buffer, indexed from 0.719/// The result is a slice of out_buffer, indexed from 0.
720pub fn getcwd(out_buffer: []u8) GetCwdError![]u8 {720pub fn getcwd(out_buffer: []u8) GetCwdError![]u8 {
721 if (windows.is_the_target and !builtin.link_libc) {721 if (windows.is_the_target) {
722 return windows.GetCurrentDirectory(out_buffer);722 return windows.GetCurrentDirectory(out_buffer);
723 }723 }
724724
...@@ -760,7 +760,7 @@ pub const SymLinkError = error{...@@ -760,7 +760,7 @@ pub const SymLinkError = error{
760/// If `sym_link_path` exists, it will not be overwritten.760/// If `sym_link_path` exists, it will not be overwritten.
761/// See also `symlinkC` and `symlinkW`.761/// See also `symlinkC` and `symlinkW`.
762pub fn symlink(target_path: []const u8, sym_link_path: []const u8) SymLinkError!void {762pub fn symlink(target_path: []const u8, sym_link_path: []const u8) SymLinkError!void {
763 if (windows.is_the_target and !builtin.link_libc) {763 if (windows.is_the_target) {
764 const target_path_w = try windows.sliceToPrefixedFileW(target_path);764 const target_path_w = try windows.sliceToPrefixedFileW(target_path);
765 const sym_link_path_w = try windows.sliceToPrefixedFileW(sym_link_path);765 const sym_link_path_w = try windows.sliceToPrefixedFileW(sym_link_path);
766 return windows.CreateSymbolicLinkW(&sym_link_path_w, &target_path_w, 0);766 return windows.CreateSymbolicLinkW(&sym_link_path_w, &target_path_w, 0);
...@@ -774,7 +774,7 @@ pub fn symlink(target_path: []const u8, sym_link_path: []const u8) SymLinkError!...@@ -774,7 +774,7 @@ pub fn symlink(target_path: []const u8, sym_link_path: []const u8) SymLinkError!
774/// This is the same as `symlink` except the parameters are null-terminated pointers.774/// This is the same as `symlink` except the parameters are null-terminated pointers.
775/// See also `symlink`.775/// See also `symlink`.
776pub fn symlinkC(target_path: [*]const u8, sym_link_path: [*]const u8) SymLinkError!void {776pub fn symlinkC(target_path: [*]const u8, sym_link_path: [*]const u8) SymLinkError!void {
777 if (windows.is_the_target and !builtin.link_libc) {777 if (windows.is_the_target) {
778 const target_path_w = try windows.cStrToPrefixedFileW(target_path);778 const target_path_w = try windows.cStrToPrefixedFileW(target_path);
779 const sym_link_path_w = try windows.cStrToPrefixedFileW(sym_link_path);779 const sym_link_path_w = try windows.cStrToPrefixedFileW(sym_link_path);
780 return windows.CreateSymbolicLinkW(&sym_link_path_w, &target_path_w, 0);780 return windows.CreateSymbolicLinkW(&sym_link_path_w, &target_path_w, 0);
...@@ -850,7 +850,7 @@ pub const UnlinkError = error{...@@ -850,7 +850,7 @@ pub const UnlinkError = error{
850/// Delete a name and possibly the file it refers to.850/// Delete a name and possibly the file it refers to.
851/// See also `unlinkC`.851/// See also `unlinkC`.
852pub fn unlink(file_path: []const u8) UnlinkError!void {852pub fn unlink(file_path: []const u8) UnlinkError!void {
853 if (windows.is_the_target and !builtin.link_libc) {853 if (windows.is_the_target) {
854 const file_path_w = try windows.sliceToPrefixedFileW(file_path);854 const file_path_w = try windows.sliceToPrefixedFileW(file_path);
855 return windows.DeleteFileW(&file_path_w);855 return windows.DeleteFileW(&file_path_w);
856 } else {856 } else {
...@@ -861,7 +861,7 @@ pub fn unlink(file_path: []const u8) UnlinkError!void {...@@ -861,7 +861,7 @@ pub fn unlink(file_path: []const u8) UnlinkError!void {
861861
862/// Same as `unlink` except the parameter is a null terminated UTF8-encoded string.862/// Same as `unlink` except the parameter is a null terminated UTF8-encoded string.
863pub fn unlinkC(file_path: [*]const u8) UnlinkError!void {863pub fn unlinkC(file_path: [*]const u8) UnlinkError!void {
864 if (windows.is_the_target and !builtin.link_libc) {864 if (windows.is_the_target) {
865 const file_path_w = try windows.cStrToPrefixedFileW(file_path);865 const file_path_w = try windows.cStrToPrefixedFileW(file_path);
866 return windows.DeleteFileW(&file_path_w);866 return windows.DeleteFileW(&file_path_w);
867 }867 }
...@@ -906,7 +906,7 @@ const RenameError = error{...@@ -906,7 +906,7 @@ const RenameError = error{
906906
907/// Change the name or location of a file.907/// Change the name or location of a file.
908pub fn rename(old_path: []const u8, new_path: []const u8) RenameError!void {908pub fn rename(old_path: []const u8, new_path: []const u8) RenameError!void {
909 if (windows.is_the_target and !builtin.link_libc) {909 if (windows.is_the_target) {
910 const old_path_w = try windows.sliceToPrefixedFileW(old_path);910 const old_path_w = try windows.sliceToPrefixedFileW(old_path);
911 const new_path_w = try windows.sliceToPrefixedFileW(new_path);911 const new_path_w = try windows.sliceToPrefixedFileW(new_path);
912 return renameW(&old_path_w, &new_path_w);912 return renameW(&old_path_w, &new_path_w);
...@@ -919,7 +919,7 @@ pub fn rename(old_path: []const u8, new_path: []const u8) RenameError!void {...@@ -919,7 +919,7 @@ pub fn rename(old_path: []const u8, new_path: []const u8) RenameError!void {
919919
920/// Same as `rename` except the parameters are null-terminated byte arrays.920/// Same as `rename` except the parameters are null-terminated byte arrays.
921pub fn renameC(old_path: [*]const u8, new_path: [*]const u8) RenameError!void {921pub fn renameC(old_path: [*]const u8, new_path: [*]const u8) RenameError!void {
922 if (windows.is_the_target and !builtin.link_libc) {922 if (windows.is_the_target) {
923 const old_path_w = try windows.cStrToPrefixedFileW(old_path);923 const old_path_w = try windows.cStrToPrefixedFileW(old_path);
924 const new_path_w = try windows.cStrToPrefixedFileW(new_path);924 const new_path_w = try windows.cStrToPrefixedFileW(new_path);
925 return renameW(&old_path_w, &new_path_w);925 return renameW(&old_path_w, &new_path_w);
...@@ -975,7 +975,7 @@ pub const MakeDirError = error{...@@ -975,7 +975,7 @@ pub const MakeDirError = error{
975/// Create a directory.975/// Create a directory.
976/// `mode` is ignored on Windows.976/// `mode` is ignored on Windows.
977pub fn mkdir(dir_path: []const u8, mode: u32) MakeDirError!void {977pub fn mkdir(dir_path: []const u8, mode: u32) MakeDirError!void {
978 if (windows.is_the_target and !builtin.link_libc) {978 if (windows.is_the_target) {
979 const dir_path_w = try windows.sliceToPrefixedFileW(dir_path);979 const dir_path_w = try windows.sliceToPrefixedFileW(dir_path);
980 return windows.CreateDirectoryW(&dir_path_w, null);980 return windows.CreateDirectoryW(&dir_path_w, null);
981 } else {981 } else {
...@@ -986,7 +986,7 @@ pub fn mkdir(dir_path: []const u8, mode: u32) MakeDirError!void {...@@ -986,7 +986,7 @@ pub fn mkdir(dir_path: []const u8, mode: u32) MakeDirError!void {
986986
987/// Same as `mkdir` but the parameter is a null-terminated UTF8-encoded string.987/// Same as `mkdir` but the parameter is a null-terminated UTF8-encoded string.
988pub fn mkdirC(dir_path: [*]const u8, mode: u32) MakeDirError!void {988pub fn mkdirC(dir_path: [*]const u8, mode: u32) MakeDirError!void {
989 if (windows.is_the_target and !builtin.link_libc) {989 if (windows.is_the_target) {
990 const dir_path_w = try windows.cStrToPrefixedFileW(dir_path);990 const dir_path_w = try windows.cStrToPrefixedFileW(dir_path);
991 return windows.CreateDirectoryW(&dir_path_w, null);991 return windows.CreateDirectoryW(&dir_path_w, null);
992 }992 }
...@@ -1026,7 +1026,7 @@ pub const DeleteDirError = error{...@@ -1026,7 +1026,7 @@ pub const DeleteDirError = error{
10261026
1027/// Deletes an empty directory.1027/// Deletes an empty directory.
1028pub fn rmdir(dir_path: []const u8) DeleteDirError!void {1028pub fn rmdir(dir_path: []const u8) DeleteDirError!void {
1029 if (windows.is_the_target and !builtin.link_libc) {1029 if (windows.is_the_target) {
1030 const dir_path_w = try windows.sliceToPrefixedFileW(dir_path);1030 const dir_path_w = try windows.sliceToPrefixedFileW(dir_path);
1031 return windows.RemoveDirectoryW(&dir_path_w);1031 return windows.RemoveDirectoryW(&dir_path_w);
1032 } else {1032 } else {
...@@ -1037,7 +1037,7 @@ pub fn rmdir(dir_path: []const u8) DeleteDirError!void {...@@ -1037,7 +1037,7 @@ pub fn rmdir(dir_path: []const u8) DeleteDirError!void {
10371037
1038/// Same as `rmdir` except the parameter is null-terminated.1038/// Same as `rmdir` except the parameter is null-terminated.
1039pub fn rmdirC(dir_path: [*]const u8) DeleteDirError!void {1039pub fn rmdirC(dir_path: [*]const u8) DeleteDirError!void {
1040 if (windows.is_the_target and !builtin.link_libc) {1040 if (windows.is_the_target) {
1041 const dir_path_w = try windows.cStrToPrefixedFileW(dir_path);1041 const dir_path_w = try windows.cStrToPrefixedFileW(dir_path);
1042 return windows.RemoveDirectoryW(&dir_path_w);1042 return windows.RemoveDirectoryW(&dir_path_w);
1043 }1043 }
...@@ -1074,7 +1074,7 @@ pub const ChangeCurDirError = error{...@@ -1074,7 +1074,7 @@ pub const ChangeCurDirError = error{
1074/// Changes the current working directory of the calling process.1074/// Changes the current working directory of the calling process.
1075/// `dir_path` is recommended to be a UTF-8 encoded string.1075/// `dir_path` is recommended to be a UTF-8 encoded string.
1076pub fn chdir(dir_path: []const u8) ChangeCurDirError!void {1076pub fn chdir(dir_path: []const u8) ChangeCurDirError!void {
1077 if (windows.is_the_target and !builtin.link_libc) {1077 if (windows.is_the_target) {
1078 const dir_path_w = try windows.sliceToPrefixedFileW(dir_path);1078 const dir_path_w = try windows.sliceToPrefixedFileW(dir_path);
1079 @compileError("TODO implement chdir for Windows");1079 @compileError("TODO implement chdir for Windows");
1080 } else {1080 } else {
...@@ -1085,7 +1085,7 @@ pub fn chdir(dir_path: []const u8) ChangeCurDirError!void {...@@ -1085,7 +1085,7 @@ pub fn chdir(dir_path: []const u8) ChangeCurDirError!void {
10851085
1086/// Same as `chdir` except the parameter is null-terminated.1086/// Same as `chdir` except the parameter is null-terminated.
1087pub fn chdirC(dir_path: [*]const u8) ChangeCurDirError!void {1087pub fn chdirC(dir_path: [*]const u8) ChangeCurDirError!void {
1088 if (windows.is_the_target and !builtin.link_libc) {1088 if (windows.is_the_target) {
1089 const dir_path_w = try windows.cStrToPrefixedFileW(dir_path);1089 const dir_path_w = try windows.cStrToPrefixedFileW(dir_path);
1090 @compileError("TODO implement chdir for Windows");1090 @compileError("TODO implement chdir for Windows");
1091 }1091 }
...@@ -1117,7 +1117,7 @@ pub const ReadLinkError = error{...@@ -1117,7 +1117,7 @@ pub const ReadLinkError = error{
1117/// Read value of a symbolic link.1117/// Read value of a symbolic link.
1118/// The return value is a slice of `out_buffer` from index 0.1118/// The return value is a slice of `out_buffer` from index 0.
1119pub fn readlink(file_path: []const u8, out_buffer: []u8) ReadLinkError![]u8 {1119pub fn readlink(file_path: []const u8, out_buffer: []u8) ReadLinkError![]u8 {
1120 if (windows.is_the_target and !builtin.link_libc) {1120 if (windows.is_the_target) {
1121 const file_path_w = try windows.sliceToPrefixedFileW(file_path);1121 const file_path_w = try windows.sliceToPrefixedFileW(file_path);
1122 @compileError("TODO implement readlink for Windows");1122 @compileError("TODO implement readlink for Windows");
1123 } else {1123 } else {
...@@ -1128,7 +1128,7 @@ pub fn readlink(file_path: []const u8, out_buffer: []u8) ReadLinkError![]u8 {...@@ -1128,7 +1128,7 @@ pub fn readlink(file_path: []const u8, out_buffer: []u8) ReadLinkError![]u8 {
11281128
1129/// Same as `readlink` except `file_path` is null-terminated.1129/// Same as `readlink` except `file_path` is null-terminated.
1130pub fn readlinkC(file_path: [*]const u8, out_buffer: []u8) ReadLinkError![]u8 {1130pub fn readlinkC(file_path: [*]const u8, out_buffer: []u8) ReadLinkError![]u8 {
1131 if (windows.is_the_target and !builtin.link_libc) {1131 if (windows.is_the_target) {
1132 const file_path_w = try windows.cStrToPrefixedFileW(file_path);1132 const file_path_w = try windows.cStrToPrefixedFileW(file_path);
1133 @compileError("TODO implement readlink for Windows");1133 @compileError("TODO implement readlink for Windows");
1134 }1134 }
...@@ -1197,9 +1197,6 @@ pub fn setregid(rgid: u32, egid: u32) SetIdError!void {...@@ -1197,9 +1197,6 @@ pub fn setregid(rgid: u32, egid: u32) SetIdError!void {
11971197
1198/// Test whether a file descriptor refers to a terminal.1198/// Test whether a file descriptor refers to a terminal.
1199pub fn isatty(handle: fd_t) bool {1199pub fn isatty(handle: fd_t) bool {
1200 if (builtin.link_libc) {
1201 return system.isatty(handle) != 0;
1202 }
1203 if (windows.is_the_target) {1200 if (windows.is_the_target) {
1204 if (isCygwinPty(handle))1201 if (isCygwinPty(handle))
1205 return true;1202 return true;
...@@ -1207,6 +1204,9 @@ pub fn isatty(handle: fd_t) bool {...@@ -1207,6 +1204,9 @@ pub fn isatty(handle: fd_t) bool {
1207 var out: windows.DWORD = undefined;1204 var out: windows.DWORD = undefined;
1208 return windows.kernel32.GetConsoleMode(handle, &out) != 0;1205 return windows.kernel32.GetConsoleMode(handle, &out) != 0;
1209 }1206 }
1207 if (builtin.link_libc) {
1208 return system.isatty(handle) != 0;
1209 }
1210 if (wasi.is_the_target) {1210 if (wasi.is_the_target) {
1211 @compileError("TODO implement std.os.isatty for WASI");1211 @compileError("TODO implement std.os.isatty for WASI");
1212 }1212 }
...@@ -2003,7 +2003,7 @@ pub const AccessError = error{...@@ -2003,7 +2003,7 @@ pub const AccessError = error{
2003/// check user's permissions for a file2003/// check user's permissions for a file
2004/// TODO currently this assumes `mode` is `F_OK` on Windows.2004/// TODO currently this assumes `mode` is `F_OK` on Windows.
2005pub fn access(path: []const u8, mode: u32) AccessError!void {2005pub fn access(path: []const u8, mode: u32) AccessError!void {
2006 if (windows.is_the_target and !builtin.link_libc) {2006 if (windows.is_the_target) {
2007 const path_w = try windows.sliceToPrefixedFileW(path);2007 const path_w = try windows.sliceToPrefixedFileW(path);
2008 _ = try windows.GetFileAttributesW(&path_w);2008 _ = try windows.GetFileAttributesW(&path_w);
2009 return;2009 return;
...@@ -2014,7 +2014,7 @@ pub fn access(path: []const u8, mode: u32) AccessError!void {...@@ -2014,7 +2014,7 @@ pub fn access(path: []const u8, mode: u32) AccessError!void {
20142014
2015/// Same as `access` except `path` is null-terminated.2015/// Same as `access` except `path` is null-terminated.
2016pub fn accessC(path: [*]const u8, mode: u32) AccessError!void {2016pub fn accessC(path: [*]const u8, mode: u32) AccessError!void {
2017 if (windows.is_the_target and !builtin.link_libc) {2017 if (windows.is_the_target) {
2018 const path_w = try windows.cStrToPrefixedFileW(path);2018 const path_w = try windows.cStrToPrefixedFileW(path);
2019 _ = try windows.GetFileAttributesW(&path_w);2019 _ = try windows.GetFileAttributesW(&path_w);
2020 return;2020 return;
...@@ -2132,7 +2132,7 @@ pub fn lseek_SET(fd: fd_t, offset: u64) SeekError!void {...@@ -2132,7 +2132,7 @@ pub fn lseek_SET(fd: fd_t, offset: u64) SeekError!void {
2132 else => |err| return unexpectedErrno(err),2132 else => |err| return unexpectedErrno(err),
2133 }2133 }
2134 }2134 }
2135 if (windows.is_the_target and !builtin.link_libc) {2135 if (windows.is_the_target) {
2136 return windows.SetFilePointerEx_BEGIN(fd, offset);2136 return windows.SetFilePointerEx_BEGIN(fd, offset);
2137 }2137 }
2138 const ipos = @bitCast(i64, offset); // the OS treats this as unsigned2138 const ipos = @bitCast(i64, offset); // the OS treats this as unsigned
...@@ -2160,7 +2160,7 @@ pub fn lseek_CUR(fd: fd_t, offset: i64) SeekError!void {...@@ -2160,7 +2160,7 @@ pub fn lseek_CUR(fd: fd_t, offset: i64) SeekError!void {
2160 else => |err| return unexpectedErrno(err),2160 else => |err| return unexpectedErrno(err),
2161 }2161 }
2162 }2162 }
2163 if (windows.is_the_target and !builtin.link_libc) {2163 if (windows.is_the_target) {
2164 return windows.SetFilePointerEx_CURRENT(fd, offset);2164 return windows.SetFilePointerEx_CURRENT(fd, offset);
2165 }2165 }
2166 switch (errno(system.lseek(fd, offset, SEEK_CUR))) {2166 switch (errno(system.lseek(fd, offset, SEEK_CUR))) {
...@@ -2186,7 +2186,7 @@ pub fn lseek_END(fd: fd_t, offset: i64) SeekError!void {...@@ -2186,7 +2186,7 @@ pub fn lseek_END(fd: fd_t, offset: i64) SeekError!void {
2186 else => |err| return unexpectedErrno(err),2186 else => |err| return unexpectedErrno(err),
2187 }2187 }
2188 }2188 }
2189 if (windows.is_the_target and !builtin.link_libc) {2189 if (windows.is_the_target) {
2190 return windows.SetFilePointerEx_END(fd, offset);2190 return windows.SetFilePointerEx_END(fd, offset);
2191 }2191 }
2192 switch (errno(system.lseek(fd, offset, SEEK_END))) {2192 switch (errno(system.lseek(fd, offset, SEEK_END))) {
...@@ -2214,7 +2214,7 @@ pub fn lseek_CUR_get(fd: fd_t) SeekError!u64 {...@@ -2214,7 +2214,7 @@ pub fn lseek_CUR_get(fd: fd_t) SeekError!u64 {
2214 else => |err| return unexpectedErrno(err),2214 else => |err| return unexpectedErrno(err),
2215 }2215 }
2216 }2216 }
2217 if (windows.is_the_target and !builtin.link_libc) {2217 if (windows.is_the_target) {
2218 return windows.SetFilePointerEx_CURRENT_get(fd);2218 return windows.SetFilePointerEx_CURRENT_get(fd);
2219 }2219 }
2220 const rc = system.lseek(fd, 0, SEEK_CUR);2220 const rc = system.lseek(fd, 0, SEEK_CUR);
std/time.zig+1-1
...@@ -30,7 +30,7 @@ pub fn timestamp() u64 {...@@ -30,7 +30,7 @@ pub fn timestamp() u64 {
30/// Get the posix timestamp, UTC, in milliseconds30/// Get the posix timestamp, UTC, in milliseconds
31/// TODO audit this function. is it possible to return an error?31/// TODO audit this function. is it possible to return an error?
32pub fn milliTimestamp() u64 {32pub fn milliTimestamp() u64 {
33 if (os.windows.is_the_target and !builtin.link_libc) {33 if (os.windows.is_the_target) {
34 //FileTime has a granularity of 100 nanoseconds34 //FileTime has a granularity of 100 nanoseconds
35 // and uses the NTFS/Windows epoch35 // and uses the NTFS/Windows epoch
36 var ft: os.windows.FILETIME = undefined;36 var ft: os.windows.FILETIME = undefined;