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{
718718
719719/// The result is a slice of out_buffer, indexed from 0.
720720pub fn getcwd(out_buffer: []u8) GetCwdError![]u8 {
721 if (windows.is_the_target and !builtin.link_libc) {
721 if (windows.is_the_target) {
722722 return windows.GetCurrentDirectory(out_buffer);
723723 }
724724
......@@ -760,7 +760,7 @@ pub const SymLinkError = error{
760760/// If `sym_link_path` exists, it will not be overwritten.
761761/// See also `symlinkC` and `symlinkW`.
762762pub 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) {
764764 const target_path_w = try windows.sliceToPrefixedFileW(target_path);
765765 const sym_link_path_w = try windows.sliceToPrefixedFileW(sym_link_path);
766766 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!
774774/// This is the same as `symlink` except the parameters are null-terminated pointers.
775775/// See also `symlink`.
776776pub 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) {
778778 const target_path_w = try windows.cStrToPrefixedFileW(target_path);
779779 const sym_link_path_w = try windows.cStrToPrefixedFileW(sym_link_path);
780780 return windows.CreateSymbolicLinkW(&sym_link_path_w, &target_path_w, 0);
......@@ -850,7 +850,7 @@ pub const UnlinkError = error{
850850/// Delete a name and possibly the file it refers to.
851851/// See also `unlinkC`.
852852pub fn unlink(file_path: []const u8) UnlinkError!void {
853 if (windows.is_the_target and !builtin.link_libc) {
853 if (windows.is_the_target) {
854854 const file_path_w = try windows.sliceToPrefixedFileW(file_path);
855855 return windows.DeleteFileW(&file_path_w);
856856 } else {
......@@ -861,7 +861,7 @@ pub fn unlink(file_path: []const u8) UnlinkError!void {
861861
862862/// Same as `unlink` except the parameter is a null terminated UTF8-encoded string.
863863pub fn unlinkC(file_path: [*]const u8) UnlinkError!void {
864 if (windows.is_the_target and !builtin.link_libc) {
864 if (windows.is_the_target) {
865865 const file_path_w = try windows.cStrToPrefixedFileW(file_path);
866866 return windows.DeleteFileW(&file_path_w);
867867 }
......@@ -906,7 +906,7 @@ const RenameError = error{
906906
907907/// Change the name or location of a file.
908908pub 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) {
910910 const old_path_w = try windows.sliceToPrefixedFileW(old_path);
911911 const new_path_w = try windows.sliceToPrefixedFileW(new_path);
912912 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 {
919919
920920/// Same as `rename` except the parameters are null-terminated byte arrays.
921921pub 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) {
923923 const old_path_w = try windows.cStrToPrefixedFileW(old_path);
924924 const new_path_w = try windows.cStrToPrefixedFileW(new_path);
925925 return renameW(&old_path_w, &new_path_w);
......@@ -975,7 +975,7 @@ pub const MakeDirError = error{
975975/// Create a directory.
976976/// `mode` is ignored on Windows.
977977pub 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) {
979979 const dir_path_w = try windows.sliceToPrefixedFileW(dir_path);
980980 return windows.CreateDirectoryW(&dir_path_w, null);
981981 } else {
......@@ -986,7 +986,7 @@ pub fn mkdir(dir_path: []const u8, mode: u32) MakeDirError!void {
986986
987987/// Same as `mkdir` but the parameter is a null-terminated UTF8-encoded string.
988988pub 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) {
990990 const dir_path_w = try windows.cStrToPrefixedFileW(dir_path);
991991 return windows.CreateDirectoryW(&dir_path_w, null);
992992 }
......@@ -1026,7 +1026,7 @@ pub const DeleteDirError = error{
10261026
10271027/// Deletes an empty directory.
10281028pub fn rmdir(dir_path: []const u8) DeleteDirError!void {
1029 if (windows.is_the_target and !builtin.link_libc) {
1029 if (windows.is_the_target) {
10301030 const dir_path_w = try windows.sliceToPrefixedFileW(dir_path);
10311031 return windows.RemoveDirectoryW(&dir_path_w);
10321032 } else {
......@@ -1037,7 +1037,7 @@ pub fn rmdir(dir_path: []const u8) DeleteDirError!void {
10371037
10381038/// Same as `rmdir` except the parameter is null-terminated.
10391039pub fn rmdirC(dir_path: [*]const u8) DeleteDirError!void {
1040 if (windows.is_the_target and !builtin.link_libc) {
1040 if (windows.is_the_target) {
10411041 const dir_path_w = try windows.cStrToPrefixedFileW(dir_path);
10421042 return windows.RemoveDirectoryW(&dir_path_w);
10431043 }
......@@ -1074,7 +1074,7 @@ pub const ChangeCurDirError = error{
10741074/// Changes the current working directory of the calling process.
10751075/// `dir_path` is recommended to be a UTF-8 encoded string.
10761076pub fn chdir(dir_path: []const u8) ChangeCurDirError!void {
1077 if (windows.is_the_target and !builtin.link_libc) {
1077 if (windows.is_the_target) {
10781078 const dir_path_w = try windows.sliceToPrefixedFileW(dir_path);
10791079 @compileError("TODO implement chdir for Windows");
10801080 } else {
......@@ -1085,7 +1085,7 @@ pub fn chdir(dir_path: []const u8) ChangeCurDirError!void {
10851085
10861086/// Same as `chdir` except the parameter is null-terminated.
10871087pub fn chdirC(dir_path: [*]const u8) ChangeCurDirError!void {
1088 if (windows.is_the_target and !builtin.link_libc) {
1088 if (windows.is_the_target) {
10891089 const dir_path_w = try windows.cStrToPrefixedFileW(dir_path);
10901090 @compileError("TODO implement chdir for Windows");
10911091 }
......@@ -1117,7 +1117,7 @@ pub const ReadLinkError = error{
11171117/// Read value of a symbolic link.
11181118/// The return value is a slice of `out_buffer` from index 0.
11191119pub 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) {
11211121 const file_path_w = try windows.sliceToPrefixedFileW(file_path);
11221122 @compileError("TODO implement readlink for Windows");
11231123 } else {
......@@ -1128,7 +1128,7 @@ pub fn readlink(file_path: []const u8, out_buffer: []u8) ReadLinkError![]u8 {
11281128
11291129/// Same as `readlink` except `file_path` is null-terminated.
11301130pub 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) {
11321132 const file_path_w = try windows.cStrToPrefixedFileW(file_path);
11331133 @compileError("TODO implement readlink for Windows");
11341134 }
......@@ -1197,9 +1197,6 @@ pub fn setregid(rgid: u32, egid: u32) SetIdError!void {
11971197
11981198/// Test whether a file descriptor refers to a terminal.
11991199pub fn isatty(handle: fd_t) bool {
1200 if (builtin.link_libc) {
1201 return system.isatty(handle) != 0;
1202 }
12031200 if (windows.is_the_target) {
12041201 if (isCygwinPty(handle))
12051202 return true;
......@@ -1207,6 +1204,9 @@ pub fn isatty(handle: fd_t) bool {
12071204 var out: windows.DWORD = undefined;
12081205 return windows.kernel32.GetConsoleMode(handle, &out) != 0;
12091206 }
1207 if (builtin.link_libc) {
1208 return system.isatty(handle) != 0;
1209 }
12101210 if (wasi.is_the_target) {
12111211 @compileError("TODO implement std.os.isatty for WASI");
12121212 }
......@@ -2003,7 +2003,7 @@ pub const AccessError = error{
20032003/// check user's permissions for a file
20042004/// TODO currently this assumes `mode` is `F_OK` on Windows.
20052005pub 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) {
20072007 const path_w = try windows.sliceToPrefixedFileW(path);
20082008 _ = try windows.GetFileAttributesW(&path_w);
20092009 return;
......@@ -2014,7 +2014,7 @@ pub fn access(path: []const u8, mode: u32) AccessError!void {
20142014
20152015/// Same as `access` except `path` is null-terminated.
20162016pub 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) {
20182018 const path_w = try windows.cStrToPrefixedFileW(path);
20192019 _ = try windows.GetFileAttributesW(&path_w);
20202020 return;
......@@ -2132,7 +2132,7 @@ pub fn lseek_SET(fd: fd_t, offset: u64) SeekError!void {
21322132 else => |err| return unexpectedErrno(err),
21332133 }
21342134 }
2135 if (windows.is_the_target and !builtin.link_libc) {
2135 if (windows.is_the_target) {
21362136 return windows.SetFilePointerEx_BEGIN(fd, offset);
21372137 }
21382138 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 {
21602160 else => |err| return unexpectedErrno(err),
21612161 }
21622162 }
2163 if (windows.is_the_target and !builtin.link_libc) {
2163 if (windows.is_the_target) {
21642164 return windows.SetFilePointerEx_CURRENT(fd, offset);
21652165 }
21662166 switch (errno(system.lseek(fd, offset, SEEK_CUR))) {
......@@ -2186,7 +2186,7 @@ pub fn lseek_END(fd: fd_t, offset: i64) SeekError!void {
21862186 else => |err| return unexpectedErrno(err),
21872187 }
21882188 }
2189 if (windows.is_the_target and !builtin.link_libc) {
2189 if (windows.is_the_target) {
21902190 return windows.SetFilePointerEx_END(fd, offset);
21912191 }
21922192 switch (errno(system.lseek(fd, offset, SEEK_END))) {
......@@ -2214,7 +2214,7 @@ pub fn lseek_CUR_get(fd: fd_t) SeekError!u64 {
22142214 else => |err| return unexpectedErrno(err),
22152215 }
22162216 }
2217 if (windows.is_the_target and !builtin.link_libc) {
2217 if (windows.is_the_target) {
22182218 return windows.SetFilePointerEx_CURRENT_get(fd);
22192219 }
22202220 const rc = system.lseek(fd, 0, SEEK_CUR);
std/time.zig+1-1
......@@ -30,7 +30,7 @@ pub fn timestamp() u64 {
3030/// Get the posix timestamp, UTC, in milliseconds
3131/// TODO audit this function. is it possible to return an error?
3232pub fn milliTimestamp() u64 {
33 if (os.windows.is_the_target and !builtin.link_libc) {
33 if (os.windows.is_the_target) {
3434 //FileTime has a granularity of 100 nanoseconds
3535 // and uses the NTFS/Windows epoch
3636 var ft: os.windows.FILETIME = undefined;