| author | |
| committer | |
| log | 44a049e01eef654fee82a1ee4e1aaf37447319ce |
| tree | 55fe1e7ae6920f19439d4f7d3424152a133203fb |
| parent | 2f040a23c8b968db56ab4c4725d6651f5ea3418e |
| signature | Commit is signed but in an unrecognized format. |
11 files changed, 63 insertions(+), 42 deletions(-)
build.zig+1-1| ... | ... | @@ -166,7 +166,7 @@ fn dependOnLib(b: *Builder, lib_exe_obj: var, dep: LibraryDep) void { |
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | fn fileExists(filename: []const u8) !bool { |
| 169 | fs.File.access(filename) catch |err| switch (err) { | |
| 169 | fs.File.exists(filename) catch |err| switch (err) { | |
| 170 | 170 | error.PermissionDenied, |
| 171 | 171 | error.FileNotFound, |
| 172 | 172 | => return false, |
std/build.zig+1-1| ... | ... | @@ -846,7 +846,7 @@ pub const Target = union(enum) { |
| 846 | 846 | } |
| 847 | 847 | |
| 848 | 848 | pub fn oFileExt(self: Target) []const u8 { |
| 849 | const abi = switch (self.*) { | |
| 849 | const abi = switch (self) { | |
| 850 | 850 | Target.Native => builtin.abi, |
| 851 | 851 | Target.Cross => |t| t.abi, |
| 852 | 852 | }; |
std/child_process.zig+4-28| ... | ... | @@ -50,24 +50,8 @@ pub const ChildProcess = struct { |
| 50 | 50 | err_pipe: if (os.windows.is_the_target) void else [2]i32, |
| 51 | 51 | llnode: if (os.windows.is_the_target) void else LinkedList(*ChildProcess).Node, |
| 52 | 52 | |
| 53 | pub const SpawnError = error{ | |
| 54 | ProcessFdQuotaExceeded, | |
| 55 | Unexpected, | |
| 56 | NotDir, | |
| 57 | SystemResources, | |
| 58 | FileNotFound, | |
| 59 | NameTooLong, | |
| 60 | SymLinkLoop, | |
| 61 | FileSystem, | |
| 62 | OutOfMemory, | |
| 63 | AccessDenied, | |
| 64 | PermissionDenied, | |
| 65 | InvalidUserId, | |
| 66 | ResourceLimitReached, | |
| 67 | InvalidExe, | |
| 68 | IsDir, | |
| 69 | FileBusy, | |
| 70 | }; | |
| 53 | pub const SpawnError = error{OutOfMemory} || os.ExecveError || os.SetIdError || | |
| 54 | os.ChangeCurDirError || windows.CreateProcessError; | |
| 71 | 55 | |
| 72 | 56 | pub const Term = union(enum) { |
| 73 | 57 | Exited: i32, |
| ... | ... | @@ -640,7 +624,7 @@ fn windowsCreateProcess(app_name: [*]u16, cmd_line: [*]u16, envp_ptr: ?[*]u16, c |
| 640 | 624 | // However this would imply that programs compiled with -DUNICODE could not pass |
| 641 | 625 | // environment variables to programs that were not, which seems unlikely. |
| 642 | 626 | // More investigation is needed. |
| 643 | if (windows.CreateProcessW( | |
| 627 | return windows.CreateProcessW( | |
| 644 | 628 | app_name, |
| 645 | 629 | cmd_line, |
| 646 | 630 | null, |
| ... | ... | @@ -651,15 +635,7 @@ fn windowsCreateProcess(app_name: [*]u16, cmd_line: [*]u16, envp_ptr: ?[*]u16, c |
| 651 | 635 | cwd_ptr, |
| 652 | 636 | lpStartupInfo, |
| 653 | 637 | lpProcessInformation, |
| 654 | ) == 0) { | |
| 655 | switch (windows.GetLastError()) { | |
| 656 | windows.ERROR.FILE_NOT_FOUND => return error.FileNotFound, | |
| 657 | windows.ERROR.PATH_NOT_FOUND => return error.FileNotFound, | |
| 658 | windows.ERROR.INVALID_PARAMETER => unreachable, | |
| 659 | windows.ERROR.INVALID_NAME => return error.InvalidName, | |
| 660 | else => |err| return windows.unexpectedError(err), | |
| 661 | } | |
| 662 | } | |
| 638 | ); | |
| 663 | 639 | } |
| 664 | 640 | |
| 665 | 641 | /// Caller must dealloc. |
std/fs.zig+5-2| ... | ... | @@ -2,7 +2,10 @@ const builtin = @import("builtin"); |
| 2 | 2 | const std = @import("std.zig"); |
| 3 | 3 | const os = std.os; |
| 4 | 4 | const mem = std.mem; |
| 5 | const base64 = std.base64; | |
| 6 | const crypto = std.crypto; | |
| 5 | 7 | const Allocator = std.mem.Allocator; |
| 8 | const assert = std.debug.assert; | |
| 6 | 9 | |
| 7 | 10 | pub const path = @import("fs/path.zig"); |
| 8 | 11 | pub const File = @import("fs/file.zig").File; |
| ... | ... | @@ -73,7 +76,7 @@ pub fn atomicSymLink(allocator: *Allocator, existing_path: []const u8, new_path: |
| 73 | 76 | mem.copy(u8, tmp_path[0..], dirname); |
| 74 | 77 | tmp_path[dirname.len] = path.sep; |
| 75 | 78 | while (true) { |
| 76 | try getRandomBytes(rand_buf[0..]); | |
| 79 | try crypto.randomBytes(rand_buf[0..]); | |
| 77 | 80 | b64_fs_encoder.encode(tmp_path[dirname.len + 1 ..], rand_buf); |
| 78 | 81 | |
| 79 | 82 | if (symLink(existing_path, tmp_path)) { |
| ... | ... | @@ -159,7 +162,7 @@ pub const AtomicFile = struct { |
| 159 | 162 | tmp_path_buf[tmp_path_len] = 0; |
| 160 | 163 | |
| 161 | 164 | while (true) { |
| 162 | try getRandomBytes(rand_buf[0..]); | |
| 165 | try crypto.randomBytes(rand_buf[0..]); | |
| 163 | 166 | b64_fs_encoder.encode(tmp_path_buf[dirname_component_len..tmp_path_len], rand_buf); |
| 164 | 167 | |
| 165 | 168 | const file = File.openWriteNoClobberC(&tmp_path_buf, mode) catch |err| switch (err) { |
std/fs/file.zig+3-3| ... | ... | @@ -137,17 +137,17 @@ pub const File = struct { |
| 137 | 137 | |
| 138 | 138 | /// Test for the existence of `path`. |
| 139 | 139 | /// `path` is UTF8-encoded. |
| 140 | pub fn exists(path: []const u8) AccessError!void { | |
| 140 | pub fn exists(path: []const u8) !void { | |
| 141 | 141 | return os.access(path, os.F_OK); |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | /// Same as `exists` except the parameter is null-terminated. |
| 145 | pub fn existsC(path: [*]const u8) AccessError!void { | |
| 145 | pub fn existsC(path: [*]const u8) !void { | |
| 146 | 146 | return os.accessC(path, os.F_OK); |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | /// Same as `exists` except the parameter is null-terminated UTF16LE-encoded. |
| 150 | pub fn existsW(path: [*]const u16) AccessError!void { | |
| 150 | pub fn existsW(path: [*]const u16) !void { | |
| 151 | 151 | return os.accessW(path, os.F_OK); |
| 152 | 152 | } |
| 153 | 153 |
std/os.zig+2-1| ... | ... | @@ -86,7 +86,7 @@ pub fn close(fd: fd_t) void { |
| 86 | 86 | } |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | pub const GetRandomError = error{}; | |
| 89 | pub const GetRandomError = OpenError; | |
| 90 | 90 | |
| 91 | 91 | /// Obtain a series of random bytes. These bytes can be used to seed user-space |
| 92 | 92 | /// random number generators or for cryptographic purposes. |
| ... | ... | @@ -641,6 +641,7 @@ pub const ExecveError = error{ |
| 641 | 641 | NotDir, |
| 642 | 642 | FileBusy, |
| 643 | 643 | ProcessFdQuotaExceeded, |
| 644 | SystemFdQuotaExceeded, | |
| 644 | 645 | NameTooLong, |
| 645 | 646 | |
| 646 | 647 | Unexpected, |
std/os/bits/linux/errno.zig+1| ... | ... | @@ -279,6 +279,7 @@ pub const ESOCKTNOSUPPORT = 94; |
| 279 | 279 | |
| 280 | 280 | /// Operation not supported on transport endpoint |
| 281 | 281 | pub const EOPNOTSUPP = 95; |
| 282 | pub const ENOTSUP = EOPNOTSUPP; | |
| 282 | 283 | |
| 283 | 284 | /// Protocol family not supported |
| 284 | 285 | pub const EPFNOSUPPORT = 96; |
std/os/linux.zig+2-2| ... | ... | @@ -382,8 +382,8 @@ pub fn unlinkat(dirfd: i32, path: [*]const u8, flags: u32) usize { |
| 382 | 382 | return syscall3(SYS_unlinkat, @bitCast(usize, isize(dirfd)), @ptrToInt(path), flags); |
| 383 | 383 | } |
| 384 | 384 | |
| 385 | pub fn waitpid(pid: i32, status: *i32, options: i32) usize { | |
| 386 | return syscall4(SYS_wait4, @bitCast(usize, isize(pid)), @ptrToInt(status), @bitCast(usize, isize(options)), 0); | |
| 385 | pub fn waitpid(pid: i32, status: *i32, flags: u32) usize { | |
| 386 | return syscall4(SYS_wait4, @bitCast(usize, isize(pid)), @ptrToInt(status), flags, 0); | |
| 387 | 387 | } |
| 388 | 388 | |
| 389 | 389 | var vdso_clock_gettime = @ptrCast(?*const c_void, init_vdso_clock_gettime); |
std/os/windows.zig+40| ... | ... | @@ -1140,6 +1140,46 @@ pub fn GetEnvironmentVariableW(lpName: LPWSTR, lpBuffer: LPWSTR, nSize: DWORD) G |
| 1140 | 1140 | return rc; |
| 1141 | 1141 | } |
| 1142 | 1142 | |
| 1143 | pub const CreateProcessError = error{ | |
| 1144 | FileNotFound, | |
| 1145 | InvalidName, | |
| 1146 | Unexpected, | |
| 1147 | }; | |
| 1148 | ||
| 1149 | pub fn CreateProcessW( | |
| 1150 | lpApplicationName: ?LPWSTR, | |
| 1151 | lpCommandLine: LPWSTR, | |
| 1152 | lpProcessAttributes: ?*SECURITY_ATTRIBUTES, | |
| 1153 | lpThreadAttributes: ?*SECURITY_ATTRIBUTES, | |
| 1154 | bInheritHandles: BOOL, | |
| 1155 | dwCreationFlags: DWORD, | |
| 1156 | lpEnvironment: ?*c_void, | |
| 1157 | lpCurrentDirectory: ?LPWSTR, | |
| 1158 | lpStartupInfo: *STARTUPINFOW, | |
| 1159 | lpProcessInformation: *PROCESS_INFORMATION, | |
| 1160 | ) CreateProcessError!void { | |
| 1161 | if (kernel32.CreateProcessW( | |
| 1162 | lpApplicationName, | |
| 1163 | lpCommandLine, | |
| 1164 | lpProcessAttributes, | |
| 1165 | lpThreadAttributes, | |
| 1166 | bInheritHandle, | |
| 1167 | dwCreationFlags, | |
| 1168 | lpEnvironment, | |
| 1169 | lpCurrentDirectory, | |
| 1170 | lpStartupInfo, | |
| 1171 | lpProcessInformation, | |
| 1172 | ) == 0) { | |
| 1173 | switch (kernel32.GetLastError()) { | |
| 1174 | ERROR.FILE_NOT_FOUND => return error.FileNotFound, | |
| 1175 | ERROR.PATH_NOT_FOUND => return error.FileNotFound, | |
| 1176 | ERROR.INVALID_PARAMETER => unreachable, | |
| 1177 | ERROR.INVALID_NAME => return error.InvalidName, | |
| 1178 | else => |err| return unexpectedError(err), | |
| 1179 | } | |
| 1180 | } | |
| 1181 | } | |
| 1182 | ||
| 1143 | 1183 | pub fn cStrToPrefixedFileW(s: [*]const u8) ![PATH_MAX_WIDE + 1]u16 { |
| 1144 | 1184 | return sliceToPrefixedFileW(mem.toSliceConst(u8, s)); |
| 1145 | 1185 | } |
std/rand.zig+3-3| ... | ... | @@ -1,10 +1,10 @@ |
| 1 | // The engines provided here should be initialized from an external source. For now, getRandomBytes | |
| 2 | // from the os package is the most suitable. Be sure to use a CSPRNG when required, otherwise using | |
| 1 | // The engines provided here should be initialized from an external source. For now, randomBytes | |
| 2 | // from the crypto package is the most suitable. Be sure to use a CSPRNG when required, otherwise using | |
| 3 | 3 | // a normal PRNG will be faster and use substantially less stack space. |
| 4 | 4 | // |
| 5 | 5 | // ``` |
| 6 | 6 | // var buf: [8]u8 = undefined; |
| 7 | // try std.os.getRandomBytes(buf[0..]); | |
| 7 | // try std.crypto.randomBytes(buf[0..]); | |
| 8 | 8 | // const seed = mem.readIntSliceLittle(u64, buf[0..8]); |
| 9 | 9 | // |
| 10 | 10 | // var r = DefaultPrng.init(seed); |
test/tests.zig+1-1| ... | ... | @@ -112,7 +112,7 @@ pub fn addCliTests(b: *build.Builder, test_filter: ?[]const u8, modes: []const M |
| 112 | 112 | const exe = b.addExecutable("test-cli", "test/cli.zig"); |
| 113 | 113 | const run_cmd = exe.run(); |
| 114 | 114 | run_cmd.addArgs([][]const u8{ |
| 115 | fs.path.realAlloc(b.allocator, b.zig_exe) catch unreachable, | |
| 115 | fs.realpathAlloc(b.allocator, b.zig_exe) catch unreachable, | |
| 116 | 116 | b.pathFromRoot(b.cache_root), |
| 117 | 117 | }); |
| 118 | 118 |