authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2020-06-24 08:43:15+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2020-06-24 21:00:21+02:00
logd40e367b73c130c49b9a7b57adcac8df52a13aa7
treeaf853d0c467df262db99f9bf6f84755b99b4a6f0
parentc63b23d684ded6ad7e740df87b1aedde0bec399d

Reformat using if-else where appropriate


1 files changed, 33 insertions(+), 27 deletions(-)

lib/std/os.zig+33-27
......@@ -1667,13 +1667,13 @@ pub const UnlinkError = error{
16671667pub fn unlink(file_path: []const u8) UnlinkError!void {
16681668 if (builtin.os.tag == .wasi) {
16691669 @compileError("unlink is not supported in WASI; use unlinkat instead");
1670 }
1671 if (builtin.os.tag == .windows) {
1670 } else if (builtin.os.tag == .windows) {
16721671 const file_path_w = try windows.sliceToPrefixedFileW(file_path);
16731672 return windows.DeleteFileW(file_path_w.span().ptr);
1673 } else {
1674 const file_path_c = try toPosixPath(file_path);
1675 return unlinkZ(&file_path_c);
16741676 }
1675 const file_path_c = try toPosixPath(file_path);
1676 return unlinkZ(&file_path_c);
16771677}
16781678
16791679pub const unlinkC = @compileError("deprecated: renamed to unlinkZ");
......@@ -1874,15 +1874,15 @@ const RenameError = error{
18741874pub fn rename(old_path: []const u8, new_path: []const u8) RenameError!void {
18751875 if (builtin.os.tag == .wasi) {
18761876 @compileError("rename is not supported in WASI; use renameat instead");
1877 }
1878 if (builtin.os.tag == .windows) {
1877 } else if (builtin.os.tag == .windows) {
18791878 const old_path_w = try windows.sliceToPrefixedFileW(old_path);
18801879 const new_path_w = try windows.sliceToPrefixedFileW(new_path);
18811880 return renameW(old_path_w.span().ptr, new_path_w.span().ptr);
1881 } else {
1882 const old_path_c = try toPosixPath(old_path);
1883 const new_path_c = try toPosixPath(new_path);
1884 return renameZ(&old_path_c, &new_path_c);
18821885 }
1883 const old_path_c = try toPosixPath(old_path);
1884 const new_path_c = try toPosixPath(new_path);
1885 return renameZ(&old_path_c, &new_path_c);
18861886}
18871887
18881888pub const renameC = @compileError("deprecated: renamed to renameZ");
......@@ -2153,14 +2153,14 @@ pub fn mkdiratW(dir_fd: fd_t, sub_path_w: [*:0]const u16, mode: u32) MakeDirErro
21532153pub fn mkdir(dir_path: []const u8, mode: u32) MakeDirError!void {
21542154 if (builtin.os.tag == .wasi) {
21552155 @compileError("mkdir is not supported in WASI; use mkdirat instead");
2156 }
2157 if (builtin.os.tag == .windows) {
2156 } else if (builtin.os.tag == .windows) {
21582157 const sub_dir_handle = try windows.CreateDirectory(null, dir_path, null);
21592158 windows.CloseHandle(sub_dir_handle);
21602159 return;
2160 } else {
2161 const dir_path_c = try toPosixPath(dir_path);
2162 return mkdirZ(&dir_path_c, mode);
21612163 }
2162 const dir_path_c = try toPosixPath(dir_path);
2163 return mkdirZ(&dir_path_c, mode);
21642164}
21652165
21662166/// Same as `mkdir` but the parameter is a null-terminated UTF8-encoded string.
......@@ -2208,13 +2208,13 @@ pub const DeleteDirError = error{
22082208pub fn rmdir(dir_path: []const u8) DeleteDirError!void {
22092209 if (builtin.os.tag == .wasi) {
22102210 @compileError("rmdir is not supported in WASI; use unlinkat instead");
2211 }
2212 if (builtin.os.tag == .windows) {
2211 } else if (builtin.os.tag == .windows) {
22132212 const dir_path_w = try windows.sliceToPrefixedFileW(dir_path);
22142213 return windows.RemoveDirectoryW(dir_path_w.span().ptr);
2214 } else {
2215 const dir_path_c = try toPosixPath(dir_path);
2216 return rmdirZ(&dir_path_c);
22152217 }
2216 const dir_path_c = try toPosixPath(dir_path);
2217 return rmdirZ(&dir_path_c);
22182218}
22192219
22202220pub const rmdirC = @compileError("deprecated: renamed to rmdirZ");
......@@ -2259,13 +2259,13 @@ pub const ChangeCurDirError = error{
22592259pub fn chdir(dir_path: []const u8) ChangeCurDirError!void {
22602260 if (builtin.os.tag == .wasi) {
22612261 @compileError("chdir is not supported in WASI");
2262 }
2263 if (builtin.os.tag == .windows) {
2262 } else if (builtin.os.tag == .windows) {
22642263 const dir_path_w = try windows.sliceToPrefixedFileW(dir_path);
22652264 @compileError("TODO implement chdir for Windows");
2265 } else {
2266 const dir_path_c = try toPosixPath(dir_path);
2267 return chdirZ(&dir_path_c);
22662268 }
2267 const dir_path_c = try toPosixPath(dir_path);
2268 return chdirZ(&dir_path_c);
22692269}
22702270
22712271pub const chdirC = @compileError("deprecated: renamed to chdirZ");
......@@ -2325,13 +2325,13 @@ pub const ReadLinkError = error{
23252325pub fn readlink(file_path: []const u8, out_buffer: []u8) ReadLinkError![]u8 {
23262326 if (builtin.os.tag == .wasi) {
23272327 @compileError("readlink is not supported in WASI; use readlinkat instead");
2328 }
2329 if (builtin.os.tag == .windows) {
2328 } else if (builtin.os.tag == .windows) {
23302329 const file_path_w = try windows.sliceToPrefixedFileW(file_path);
23312330 return readlinkW(file_path_w.span().ptr, out_buffer);
2331 } else {
2332 const file_path_c = try toPosixPath(file_path);
2333 return readlinkZ(&file_path_c, out_buffer);
23322334 }
2333 const file_path_c = try toPosixPath(file_path);
2334 return readlinkZ(&file_path_c, out_buffer);
23352335}
23362336
23372337pub const readlinkC = @compileError("deprecated: renamed to readlinkZ");
......@@ -3089,6 +3089,9 @@ pub fn fstat(fd: fd_t) FStatError!Stat {
30893089 else => |err| return unexpectedErrno(err),
30903090 }
30913091 }
3092 if (builtin.os.tag == .windows) {
3093 @compileError("fstat is not yet implemented on Windows");
3094 }
30923095
30933096 var stat: Stat = undefined;
30943097 switch (errno(system.fstat(fd, &stat))) {
......@@ -3109,9 +3112,12 @@ pub const FStatAtError = FStatError || error{ NameTooLong, FileNotFound };
31093112pub fn fstatat(dirfd: fd_t, pathname: []const u8, flags: u32) FStatAtError!Stat {
31103113 if (builtin.os.tag == .wasi) {
31113114 return fstatatWasi(dirfd, pathname, flags);
3115 } else if (builtin.os.tag == .windows) {
3116 @compileError("fstatat is not yet implemented on Windows");
3117 } else {
3118 const pathname_c = try toPosixPath(pathname);
3119 return fstatatZ(dirfd, &pathname_c, flags);
31123120 }
3113 const pathname_c = try toPosixPath(pathname);
3114 return fstatatZ(dirfd, &pathname_c, flags);
31153121}
31163122
31173123pub const fstatatC = @compileError("deprecated: renamed to fstatatZ");