diff options
| author | Quetzal Bradley <qbradley@qbradley.com> | 2019-02-17 13:08:08 -0800 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2019-02-17 23:21:45 -0500 |
| commit | 7e549540527fec891bc67d5e657f82b7087530a3 (patch) | |
| tree | c534e4f2b4fbbaae2fac3575e7755e61afb64424 | |
| parent | de18ece29436290cae3608d2c942e7e0a69f1a44 (diff) | |
| download | zig-7e549540527fec891bc67d5e657f82b7087530a3.tar.gz zig-7e549540527fec891bc67d5e657f82b7087530a3.zip | |
fix openWriteNoClobber and add test
| -rw-r--r-- | std/io_test.zig | 11 | ||||
| -rw-r--r-- | std/os/file.zig | 2 |
2 files changed, 12 insertions, 1 deletions
diff --git a/std/io_test.zig b/std/io_test.zig index fb6e0ae7e9..87b970edf8 100644 --- a/std/io_test.zig +++ b/std/io_test.zig @@ -29,6 +29,17 @@ test "write a file, read it, then delete it" { try st.print("end"); try buf_stream.flush(); } + + { + // make sure openWriteNoClobber doesn't harm the file + if (os.File.openWriteNoClobber(tmp_file_name, os.File.default_mode)) |file| { + unreachable; + } + else |err| { + std.debug.assert(err == os.File.OpenError.PathAlreadyExists); + } + } + { var file = try os.File.openRead(tmp_file_name); defer file.close(); diff --git a/std/os/file.zig b/std/os/file.zig index 2ae547c694..cdd28b233c 100644 --- a/std/os/file.zig +++ b/std/os/file.zig @@ -105,7 +105,7 @@ pub const File = struct { pub fn openWriteNoClobber(path: []const u8, file_mode: Mode) OpenError!File { if (is_posix) { const path_c = try os.toPosixPath(path); - return openWriteNoClobberC(path_c, file_mode); + return openWriteNoClobberC(&path_c, file_mode); } else if (is_windows) { const path_w = try windows_util.sliceToPrefixedFileW(path); return openWriteNoClobberW(&path_w, file_mode); |
