| author | |
| committer | |
| log | 7bf740ee718f4b6109cd9fe7014d1784d48ada48 |
| tree | 0df4edc19cd18e44d78bbd7c20fe2fdf8031dd78 |
| parent | eb46bbba34c1ccb0fbbbd755fd190e1b6eb939ec |
- Rename modified `realpathW` to `realpathW2`
- Re-add original `realpathW`
- Add deprecation notice to `realpathW`3 files changed, 39 insertions(+), 8 deletions(-)
lib/std/fs.zig+2-1| ... | ... | @@ -31,6 +31,7 @@ pub const wasi = @import("fs/wasi.zig"); |
| 31 | 31 | pub const realpath = posix.realpath; |
| 32 | 32 | pub const realpathZ = posix.realpathZ; |
| 33 | 33 | pub const realpathW = posix.realpathW; |
| 34 | pub const realpathW2 = posix.realpathW2; | |
| 34 | 35 | |
| 35 | 36 | pub const getAppDataDir = @import("fs/get_app_data_dir.zig").getAppDataDir; |
| 36 | 37 | pub const GetAppDataDirError = @import("fs/get_app_data_dir.zig").GetAppDataDirError; |
| ... | ... | @@ -644,7 +645,7 @@ pub fn selfExePath(out_buffer: []u8) SelfExePathError![]u8 { |
| 644 | 645 | // that the symlink points to, though, so we need to get the realpath. |
| 645 | 646 | var pathname_w = try windows.wToPrefixedFileW(null, image_path_name); |
| 646 | 647 | |
| 647 | const wide_slice = std.fs.cwd().realpathW(pathname_w.span(), &pathname_w.data) catch |err| switch (err) { | |
| 648 | const wide_slice = std.fs.cwd().realpathW2(pathname_w.span(), &pathname_w.data) catch |err| switch (err) { | |
| 648 | 649 | error.InvalidWtf8 => unreachable, |
| 649 | 650 | else => |e| return e, |
| 650 | 651 | }; |
lib/std/fs/Dir.zig+22-3| ... | ... | @@ -1371,7 +1371,7 @@ pub fn realpath(self: Dir, pathname: []const u8, out_buffer: []u8) RealPathError |
| 1371 | 1371 | if (native_os == .windows) { |
| 1372 | 1372 | var pathname_w = try windows.sliceToPrefixedFileW(self.fd, pathname); |
| 1373 | 1373 | |
| 1374 | const wide_slice = try self.realpathW(pathname_w.span(), &pathname_w.data); | |
| 1374 | const wide_slice = try self.realpathW2(pathname_w.span(), &pathname_w.data); | |
| 1375 | 1375 | |
| 1376 | 1376 | const len = std.unicode.calcWtf8Len(wide_slice); |
| 1377 | 1377 | if (len > out_buffer.len) |
| ... | ... | @@ -1390,7 +1390,7 @@ pub fn realpathZ(self: Dir, pathname: [*:0]const u8, out_buffer: []u8) RealPathE |
| 1390 | 1390 | if (native_os == .windows) { |
| 1391 | 1391 | var pathname_w = try windows.cStrToPrefixedFileW(self.fd, pathname); |
| 1392 | 1392 | |
| 1393 | const wide_slice = try self.realpathW(pathname_w.span(), &pathname_w.data); | |
| 1393 | const wide_slice = try self.realpathW2(pathname_w.span(), &pathname_w.data); | |
| 1394 | 1394 | |
| 1395 | 1395 | const len = std.unicode.calcWtf8Len(wide_slice); |
| 1396 | 1396 | if (len > out_buffer.len) |
| ... | ... | @@ -1426,6 +1426,25 @@ pub fn realpathZ(self: Dir, pathname: [*:0]const u8, out_buffer: []u8) RealPathE |
| 1426 | 1426 | return result; |
| 1427 | 1427 | } |
| 1428 | 1428 | |
| 1429 | /// Deprecated: use `realpathW2`. | |
| 1430 | /// | |
| 1431 | /// Windows-only. Same as `Dir.realpath` except `pathname` is WTF16 LE encoded. | |
| 1432 | /// The result is encoded as [WTF-8](https://simonsapin.github.io/wtf-8/). | |
| 1433 | /// See also `Dir.realpath`, `realpathW`. | |
| 1434 | pub fn realpathW(self: Dir, pathname: []const u16, out_buffer: []u8) RealPathError![]u8 { | |
| 1435 | var wide_buf: [std.os.windows.PATH_MAX_WIDE]u16 = undefined; | |
| 1436 | ||
| 1437 | const wide_slice = try self.realpathW2(pathname, &wide_buf); | |
| 1438 | ||
| 1439 | var big_out_buf: [fs.max_path_bytes]u8 = undefined; | |
| 1440 | const end_index = std.unicode.wtf16LeToWtf8(&big_out_buf, wide_slice); | |
| 1441 | if (end_index > out_buffer.len) | |
| 1442 | return error.NameTooLong; | |
| 1443 | const result = out_buffer[0..end_index]; | |
| 1444 | @memcpy(result, big_out_buf[0..end_index]); | |
| 1445 | return result; | |
| 1446 | } | |
| 1447 | ||
| 1429 | 1448 | /// Windows-only. Same as `Dir.realpath` except |
| 1430 | 1449 | /// * `pathname` and the result are WTF-16 LE encoded |
| 1431 | 1450 | /// * `pathname` is relative or has the NT namespace prefix. See `windows.wToPrefixedFileW` for details. |
| ... | ... | @@ -1434,7 +1453,7 @@ pub fn realpathZ(self: Dir, pathname: [*:0]const u8, out_buffer: []u8) RealPathE |
| 1434 | 1453 | /// is safe to reuse a single buffer for both. |
| 1435 | 1454 | /// |
| 1436 | 1455 | /// See also `Dir.realpath`, `realpathW`. |
| 1437 | pub fn realpathW(self: Dir, pathname: []const u16, out_buffer: []u16) RealPathError![]u16 { | |
| 1456 | pub fn realpathW2(self: Dir, pathname: []const u16, out_buffer: []u16) RealPathError![]u16 { | |
| 1438 | 1457 | const w = windows; |
| 1439 | 1458 | |
| 1440 | 1459 | const access_mask = w.GENERIC_READ | w.SYNCHRONIZE; |
lib/std/posix.zig+15-4| ... | ... | @@ -5677,7 +5677,7 @@ pub fn realpath(pathname: []const u8, out_buffer: *[max_path_bytes]u8) RealPathE |
| 5677 | 5677 | if (native_os == .windows) { |
| 5678 | 5678 | var pathname_w = try windows.sliceToPrefixedFileW(null, pathname); |
| 5679 | 5679 | |
| 5680 | const wide_slice = try realpathW(pathname_w.span(), &pathname_w.data); | |
| 5680 | const wide_slice = try realpathW2(pathname_w.span(), &pathname_w.data); | |
| 5681 | 5681 | |
| 5682 | 5682 | const end_index = std.unicode.wtf16LeToWtf8(out_buffer, wide_slice); |
| 5683 | 5683 | return out_buffer[0..end_index]; |
| ... | ... | @@ -5695,7 +5695,7 @@ pub fn realpathZ(pathname: [*:0]const u8, out_buffer: *[max_path_bytes]u8) RealP |
| 5695 | 5695 | if (native_os == .windows) { |
| 5696 | 5696 | var pathname_w = try windows.cStrToPrefixedFileW(null, pathname); |
| 5697 | 5697 | |
| 5698 | const wide_slice = try realpathW(pathname_w.span(), &pathname_w.data); | |
| 5698 | const wide_slice = try realpathW2(pathname_w.span(), &pathname_w.data); | |
| 5699 | 5699 | |
| 5700 | 5700 | const end_index = std.unicode.wtf16LeToWtf8(out_buffer, wide_slice); |
| 5701 | 5701 | return out_buffer[0..end_index]; |
| ... | ... | @@ -5742,15 +5742,26 @@ pub fn realpathZ(pathname: [*:0]const u8, out_buffer: *[max_path_bytes]u8) RealP |
| 5742 | 5742 | return mem.sliceTo(result_path, 0); |
| 5743 | 5743 | } |
| 5744 | 5744 | |
| 5745 | /// Deprecated: use `realpathW2`. | |
| 5746 | /// | |
| 5745 | 5747 | /// Same as `realpath` except `pathname` is WTF16LE-encoded. |
| 5746 | 5748 | /// |
| 5747 | /// The result is encoded as WTF16LE. | |
| 5749 | /// The result is encoded as [WTF-8](https://simonsapin.github.io/wtf-8/). | |
| 5748 | 5750 | /// |
| 5749 | 5751 | /// Calling this function is usually a bug. |
| 5750 | pub fn realpathW(pathname: []const u16, out_buffer: *[std.os.windows.PATH_MAX_WIDE]u16) RealPathError![]u16 { | |
| 5752 | pub fn realpathW(pathname: []const u16, out_buffer: *[max_path_bytes]u8) RealPathError![]u8 { | |
| 5751 | 5753 | return fs.cwd().realpathW(pathname, out_buffer); |
| 5752 | 5754 | } |
| 5753 | 5755 | |
| 5756 | /// Same as `realpath` except `pathname` is WTF16LE-encoded. | |
| 5757 | /// | |
| 5758 | /// The result is encoded as WTF16LE. | |
| 5759 | /// | |
| 5760 | /// Calling this function is usually a bug. | |
| 5761 | pub fn realpathW2(pathname: []const u16, out_buffer: *[std.os.windows.PATH_MAX_WIDE]u16) RealPathError![]u16 { | |
| 5762 | return fs.cwd().realpathW2(pathname, out_buffer); | |
| 5763 | } | |
| 5764 | ||
| 5754 | 5765 | /// Spurious wakeups are possible and no precision of timing is guaranteed. |
| 5755 | 5766 | pub fn nanosleep(seconds: u64, nanoseconds: u64) void { |
| 5756 | 5767 | var req = timespec{ |