authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-05-26 13:37:34-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-05-26 18:32:45-04:00
log44a049e01eef654fee82a1ee4e1aaf37447319ce
tree55fe1e7ae6920f19439d4f7d3424152a133203fb
parent2f040a23c8b968db56ab4c4725d6651f5ea3418e
signaturelock-open Commit is signed but in an unrecognized format.

more cleanup. down to just the `@hasDecl` builtin


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,7 +166,7 @@ fn dependOnLib(b: *Builder, lib_exe_obj: var, dep: LibraryDep) void {
166}166}
167167
168fn fileExists(filename: []const u8) !bool {168fn fileExists(filename: []const u8) !bool {
169 fs.File.access(filename) catch |err| switch (err) {169 fs.File.exists(filename) catch |err| switch (err) {
170 error.PermissionDenied,170 error.PermissionDenied,
171 error.FileNotFound,171 error.FileNotFound,
172 => return false,172 => return false,
std/build.zig+1-1
...@@ -846,7 +846,7 @@ pub const Target = union(enum) {...@@ -846,7 +846,7 @@ pub const Target = union(enum) {
846 }846 }
847847
848 pub fn oFileExt(self: Target) []const u8 {848 pub fn oFileExt(self: Target) []const u8 {
849 const abi = switch (self.*) {849 const abi = switch (self) {
850 Target.Native => builtin.abi,850 Target.Native => builtin.abi,
851 Target.Cross => |t| t.abi,851 Target.Cross => |t| t.abi,
852 };852 };
std/child_process.zig+4-28
...@@ -50,24 +50,8 @@ pub const ChildProcess = struct {...@@ -50,24 +50,8 @@ pub const ChildProcess = struct {
50 err_pipe: if (os.windows.is_the_target) void else [2]i32,50 err_pipe: if (os.windows.is_the_target) void else [2]i32,
51 llnode: if (os.windows.is_the_target) void else LinkedList(*ChildProcess).Node,51 llnode: if (os.windows.is_the_target) void else LinkedList(*ChildProcess).Node,
5252
53 pub const SpawnError = error{53 pub const SpawnError = error{OutOfMemory} || os.ExecveError || os.SetIdError ||
54 ProcessFdQuotaExceeded,54 os.ChangeCurDirError || windows.CreateProcessError;
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 };
7155
72 pub const Term = union(enum) {56 pub const Term = union(enum) {
73 Exited: i32,57 Exited: i32,
...@@ -640,7 +624,7 @@ fn windowsCreateProcess(app_name: [*]u16, cmd_line: [*]u16, envp_ptr: ?[*]u16, c...@@ -640,7 +624,7 @@ fn windowsCreateProcess(app_name: [*]u16, cmd_line: [*]u16, envp_ptr: ?[*]u16, c
640 // However this would imply that programs compiled with -DUNICODE could not pass624 // However this would imply that programs compiled with -DUNICODE could not pass
641 // environment variables to programs that were not, which seems unlikely.625 // environment variables to programs that were not, which seems unlikely.
642 // More investigation is needed.626 // More investigation is needed.
643 if (windows.CreateProcessW(627 return windows.CreateProcessW(
644 app_name,628 app_name,
645 cmd_line,629 cmd_line,
646 null,630 null,
...@@ -651,15 +635,7 @@ fn windowsCreateProcess(app_name: [*]u16, cmd_line: [*]u16, envp_ptr: ?[*]u16, c...@@ -651,15 +635,7 @@ fn windowsCreateProcess(app_name: [*]u16, cmd_line: [*]u16, envp_ptr: ?[*]u16, c
651 cwd_ptr,635 cwd_ptr,
652 lpStartupInfo,636 lpStartupInfo,
653 lpProcessInformation,637 lpProcessInformation,
654 ) == 0) {638 );
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 }
663}639}
664640
665/// Caller must dealloc.641/// Caller must dealloc.
std/fs.zig+5-2
...@@ -2,7 +2,10 @@ const builtin = @import("builtin");...@@ -2,7 +2,10 @@ const builtin = @import("builtin");
2const std = @import("std.zig");2const std = @import("std.zig");
3const os = std.os;3const os = std.os;
4const mem = std.mem;4const mem = std.mem;
5const base64 = std.base64;
6const crypto = std.crypto;
5const Allocator = std.mem.Allocator;7const Allocator = std.mem.Allocator;
8const assert = std.debug.assert;
69
7pub const path = @import("fs/path.zig");10pub const path = @import("fs/path.zig");
8pub const File = @import("fs/file.zig").File;11pub const File = @import("fs/file.zig").File;
...@@ -73,7 +76,7 @@ pub fn atomicSymLink(allocator: *Allocator, existing_path: []const u8, new_path:...@@ -73,7 +76,7 @@ pub fn atomicSymLink(allocator: *Allocator, existing_path: []const u8, new_path:
73 mem.copy(u8, tmp_path[0..], dirname);76 mem.copy(u8, tmp_path[0..], dirname);
74 tmp_path[dirname.len] = path.sep;77 tmp_path[dirname.len] = path.sep;
75 while (true) {78 while (true) {
76 try getRandomBytes(rand_buf[0..]);79 try crypto.randomBytes(rand_buf[0..]);
77 b64_fs_encoder.encode(tmp_path[dirname.len + 1 ..], rand_buf);80 b64_fs_encoder.encode(tmp_path[dirname.len + 1 ..], rand_buf);
7881
79 if (symLink(existing_path, tmp_path)) {82 if (symLink(existing_path, tmp_path)) {
...@@ -159,7 +162,7 @@ pub const AtomicFile = struct {...@@ -159,7 +162,7 @@ pub const AtomicFile = struct {
159 tmp_path_buf[tmp_path_len] = 0;162 tmp_path_buf[tmp_path_len] = 0;
160163
161 while (true) {164 while (true) {
162 try getRandomBytes(rand_buf[0..]);165 try crypto.randomBytes(rand_buf[0..]);
163 b64_fs_encoder.encode(tmp_path_buf[dirname_component_len..tmp_path_len], rand_buf);166 b64_fs_encoder.encode(tmp_path_buf[dirname_component_len..tmp_path_len], rand_buf);
164167
165 const file = File.openWriteNoClobberC(&tmp_path_buf, mode) catch |err| switch (err) {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,17 +137,17 @@ pub const File = struct {
137137
138 /// Test for the existence of `path`.138 /// Test for the existence of `path`.
139 /// `path` is UTF8-encoded.139 /// `path` is UTF8-encoded.
140 pub fn exists(path: []const u8) AccessError!void {140 pub fn exists(path: []const u8) !void {
141 return os.access(path, os.F_OK);141 return os.access(path, os.F_OK);
142 }142 }
143143
144 /// Same as `exists` except the parameter is null-terminated.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 return os.accessC(path, os.F_OK);146 return os.accessC(path, os.F_OK);
147 }147 }
148148
149 /// Same as `exists` except the parameter is null-terminated UTF16LE-encoded.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 return os.accessW(path, os.F_OK);151 return os.accessW(path, os.F_OK);
152 }152 }
153153
std/os.zig+2-1
...@@ -86,7 +86,7 @@ pub fn close(fd: fd_t) void {...@@ -86,7 +86,7 @@ pub fn close(fd: fd_t) void {
86 }86 }
87}87}
8888
89pub const GetRandomError = error{};89pub const GetRandomError = OpenError;
9090
91/// Obtain a series of random bytes. These bytes can be used to seed user-space91/// Obtain a series of random bytes. These bytes can be used to seed user-space
92/// random number generators or for cryptographic purposes.92/// random number generators or for cryptographic purposes.
...@@ -641,6 +641,7 @@ pub const ExecveError = error{...@@ -641,6 +641,7 @@ pub const ExecveError = error{
641 NotDir,641 NotDir,
642 FileBusy,642 FileBusy,
643 ProcessFdQuotaExceeded,643 ProcessFdQuotaExceeded,
644 SystemFdQuotaExceeded,
644 NameTooLong,645 NameTooLong,
645646
646 Unexpected,647 Unexpected,
std/os/bits/linux/errno.zig+1
...@@ -279,6 +279,7 @@ pub const ESOCKTNOSUPPORT = 94;...@@ -279,6 +279,7 @@ pub const ESOCKTNOSUPPORT = 94;
279279
280/// Operation not supported on transport endpoint280/// Operation not supported on transport endpoint
281pub const EOPNOTSUPP = 95;281pub const EOPNOTSUPP = 95;
282pub const ENOTSUP = EOPNOTSUPP;
282283
283/// Protocol family not supported284/// Protocol family not supported
284pub const EPFNOSUPPORT = 96;285pub 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,8 +382,8 @@ pub fn unlinkat(dirfd: i32, path: [*]const u8, flags: u32) usize {
382 return syscall3(SYS_unlinkat, @bitCast(usize, isize(dirfd)), @ptrToInt(path), flags);382 return syscall3(SYS_unlinkat, @bitCast(usize, isize(dirfd)), @ptrToInt(path), flags);
383}383}
384384
385pub fn waitpid(pid: i32, status: *i32, options: i32) usize {385pub fn waitpid(pid: i32, status: *i32, flags: u32) usize {
386 return syscall4(SYS_wait4, @bitCast(usize, isize(pid)), @ptrToInt(status), @bitCast(usize, isize(options)), 0);386 return syscall4(SYS_wait4, @bitCast(usize, isize(pid)), @ptrToInt(status), flags, 0);
387}387}
388388
389var vdso_clock_gettime = @ptrCast(?*const c_void, init_vdso_clock_gettime);389var 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,6 +1140,46 @@ pub fn GetEnvironmentVariableW(lpName: LPWSTR, lpBuffer: LPWSTR, nSize: DWORD) G
1140 return rc;1140 return rc;
1141}1141}
11421142
1143pub const CreateProcessError = error{
1144 FileNotFound,
1145 InvalidName,
1146 Unexpected,
1147};
1148
1149pub 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
1143pub fn cStrToPrefixedFileW(s: [*]const u8) ![PATH_MAX_WIDE + 1]u16 {1183pub fn cStrToPrefixedFileW(s: [*]const u8) ![PATH_MAX_WIDE + 1]u16 {
1144 return sliceToPrefixedFileW(mem.toSliceConst(u8, s));1184 return sliceToPrefixedFileW(mem.toSliceConst(u8, s));
1145}1185}
std/rand.zig+3-3
...@@ -1,10 +1,10 @@...@@ -1,10 +1,10 @@
1// The engines provided here should be initialized from an external source. For now, getRandomBytes1// The engines provided here should be initialized from an external source. For now, randomBytes
2// from the os package is the most suitable. Be sure to use a CSPRNG when required, otherwise using2// from the crypto package is the most suitable. Be sure to use a CSPRNG when required, otherwise using
3// a normal PRNG will be faster and use substantially less stack space.3// a normal PRNG will be faster and use substantially less stack space.
4//4//
5// ```5// ```
6// var buf: [8]u8 = undefined;6// var buf: [8]u8 = undefined;
7// try std.os.getRandomBytes(buf[0..]);7// try std.crypto.randomBytes(buf[0..]);
8// const seed = mem.readIntSliceLittle(u64, buf[0..8]);8// const seed = mem.readIntSliceLittle(u64, buf[0..8]);
9//9//
10// var r = DefaultPrng.init(seed);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,7 +112,7 @@ pub fn addCliTests(b: *build.Builder, test_filter: ?[]const u8, modes: []const M
112 const exe = b.addExecutable("test-cli", "test/cli.zig");112 const exe = b.addExecutable("test-cli", "test/cli.zig");
113 const run_cmd = exe.run();113 const run_cmd = exe.run();
114 run_cmd.addArgs([][]const u8{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 b.pathFromRoot(b.cache_root),116 b.pathFromRoot(b.cache_root),
117 });117 });
118118