Skip to content

Commit 333e1a7

Browse files
committed
Deal with wine paths in GetFinalPathNameByHandle
When calling QueryObjectName, Wine returns NT namespaced paths. This change appropriately strips the prefix to turn it into an absolute path.
1 parent 7abf9b3 commit 333e1a7

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

lib/std/os/windows.zig

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1224,7 +1224,21 @@ pub fn GetFinalPathNameByHandle(
12241224
// TODO find out if a path can start with something besides `\Device\<volume name>`,
12251225
// and if we need to handle it differently
12261226
// (i.e. how to determine the start and end of the volume name in that case)
1227-
if (!mem.eql(u16, expected_prefix, final_path[0..expected_prefix.len])) return error.Unexpected;
1227+
if (!mem.eql(u16, expected_prefix, final_path[0..expected_prefix.len])) {
1228+
// Wine seems to return NT namespaced paths from QueryObjectName
1229+
// (e.g. `\??\Z:\some\path\to\a\file.txt`), in which case we can just strip the
1230+
// prefix to turn it into an absolute path
1231+
if (getNamespacePrefix(u16, final_path) == .nt) {
1232+
const unprefixed_path = final_path[4..];
1233+
// TODO: Handle other possible path types, only drive absolute has been observed so far
1234+
if (getUnprefixedPathType(unprefixed_path) != .drive_absolute) {
1235+
return error.Unexpected;
1236+
}
1237+
mem.copyForwards(u16, out_buffer[0..unprefixed_path.len], unprefixed_path);
1238+
return out_buffer[0..unprefixed_path.len];
1239+
}
1240+
return error.Unexpected;
1241+
}
12281242

12291243
const file_path_begin_index = mem.indexOfPos(u16, final_path, expected_prefix.len, &[_]u16{'\\'}) orelse unreachable;
12301244
const volume_name_u16 = final_path[0..file_path_begin_index];

0 commit comments

Comments
 (0)