authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-04-27 13:39:06-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-04-27 13:39:06-04:00
log1e04e852009b969741e2969f2aeedb72d73d326a
tree9c69fecdb9f9448345527f90882bce7648faf713
parent41e17106cdcb0bc19f26ef67ebe2d98d920ee21b

std: support `/` in Windows paths


1 files changed, 12 insertions(+), 7 deletions(-)

lib/std/os/windows.zig+12-7
......@@ -1260,15 +1260,9 @@ pub fn wToPrefixedFileW(s: []const u16) ![PATH_MAX_WIDE:0]u16 {
12601260pub fn sliceToPrefixedSuffixedFileW(s: []const u8, comptime suffix: []const u16) ![PATH_MAX_WIDE + suffix.len:0]u16 {
12611261 // TODO https://github.com/ziglang/zig/issues/2765
12621262 var result: [PATH_MAX_WIDE + suffix.len:0]u16 = undefined;
1263 // > File I/O functions in the Windows API convert "/" to "\" as part of
1264 // > converting the name to an NT-style name, except when using the "\\?\"
1265 // > prefix as detailed in the following sections.
1266 // from https://docs.microsoft.com/en-us/windows/desktop/FileIO/naming-a-file#maximum-path-length-limitation
1267 // Because we want the larger maximum path length for absolute paths, we
1268 // disallow forward slashes in zig std lib file functions on Windows.
12691263 for (s) |byte| {
12701264 switch (byte) {
1271 '/', '*', '?', '"', '<', '>', '|' => return error.BadPathName,
1265 '*', '?', '"', '<', '>', '|' => return error.BadPathName,
12721266 else => {},
12731267 }
12741268 }
......@@ -1279,6 +1273,17 @@ pub fn sliceToPrefixedSuffixedFileW(s: []const u8, comptime suffix: []const u16)
12791273 };
12801274 const end_index = start_index + try std.unicode.utf8ToUtf16Le(result[start_index..], s);
12811275 if (end_index + suffix.len > result.len) return error.NameTooLong;
1276 // > File I/O functions in the Windows API convert "/" to "\" as part of
1277 // > converting the name to an NT-style name, except when using the "\\?\"
1278 // > prefix as detailed in the following sections.
1279 // from https://docs.microsoft.com/en-us/windows/desktop/FileIO/naming-a-file#maximum-path-length-limitation
1280 // Because we want the larger maximum path length for absolute paths, we
1281 // convert forward slashes to backward slashes here.
1282 for (result[0..end_index]) |*elem| {
1283 if (elem.* == '/') {
1284 elem.* = '\\';
1285 }
1286 }
12821287 mem.copy(u16, result[end_index..], suffix);
12831288 result[end_index + suffix.len] = 0;
12841289 return result;