| ... | @@ -1260,15 +1260,9 @@ pub fn wToPrefixedFileW(s: []const u16) ![PATH_MAX_WIDE:0]u16 { | ... | @@ -1260,15 +1260,9 @@ pub fn wToPrefixedFileW(s: []const u16) ![PATH_MAX_WIDE:0]u16 { |
| 1260 | pub fn sliceToPrefixedSuffixedFileW(s: []const u8, comptime suffix: []const u16) ![PATH_MAX_WIDE + suffix.len:0]u16 { | 1260 | pub fn sliceToPrefixedSuffixedFileW(s: []const u8, comptime suffix: []const u16) ![PATH_MAX_WIDE + suffix.len:0]u16 { |
| 1261 | // TODO https://github.com/ziglang/zig/issues/2765 | 1261 | // TODO https://github.com/ziglang/zig/issues/2765 |
| 1262 | var result: [PATH_MAX_WIDE + suffix.len:0]u16 = undefined; | 1262 | 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. | | |
| 1269 | for (s) |byte| { | 1263 | for (s) |byte| { |
| 1270 | switch (byte) { | 1264 | switch (byte) { |
| 1271 | '/', '*', '?', '"', '<', '>', '|' => return error.BadPathName, | 1265 | '*', '?', '"', '<', '>', '|' => return error.BadPathName, |
| 1272 | else => {}, | 1266 | else => {}, |
| 1273 | } | 1267 | } |
| 1274 | } | 1268 | } |
| ... | @@ -1279,6 +1273,17 @@ pub fn sliceToPrefixedSuffixedFileW(s: []const u8, comptime suffix: []const u16) | ... | @@ -1279,6 +1273,17 @@ pub fn sliceToPrefixedSuffixedFileW(s: []const u8, comptime suffix: []const u16) |
| 1279 | }; | 1273 | }; |
| 1280 | const end_index = start_index + try std.unicode.utf8ToUtf16Le(result[start_index..], s); | 1274 | const end_index = start_index + try std.unicode.utf8ToUtf16Le(result[start_index..], s); |
| 1281 | if (end_index + suffix.len > result.len) return error.NameTooLong; | 1275 | 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 | } |
| 1282 | mem.copy(u16, result[end_index..], suffix); | 1287 | mem.copy(u16, result[end_index..], suffix); |
| 1283 | result[end_index + suffix.len] = 0; | 1288 | result[end_index + suffix.len] = 0; |
| 1284 | return result; | 1289 | return result; |