@@ -1371,7 +1371,7 @@ pub fn realpath(self: Dir, pathname: []const u8, out_buffer: []u8) RealPathError
13711371 if (native_os == .windows ) {
13721372 var pathname_w = try windows .sliceToPrefixedFileW (self .fd , pathname );
13731373
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 );
13751375
13761376 const len = std .unicode .calcWtf8Len (wide_slice );
13771377 if (len > out_buffer .len )
@@ -1390,7 +1390,7 @@ pub fn realpathZ(self: Dir, pathname: [*:0]const u8, out_buffer: []u8) RealPathE
13901390 if (native_os == .windows ) {
13911391 var pathname_w = try windows .cStrToPrefixedFileW (self .fd , pathname );
13921392
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 );
13941394
13951395 const len = std .unicode .calcWtf8Len (wide_slice );
13961396 if (len > out_buffer .len )
@@ -1426,6 +1426,25 @@ pub fn realpathZ(self: Dir, pathname: [*:0]const u8, out_buffer: []u8) RealPathE
14261426 return result ;
14271427}
14281428
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+
14291448/// Windows-only. Same as `Dir.realpath` except
14301449/// * `pathname` and the result are WTF-16 LE encoded
14311450/// * `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
14341453/// is safe to reuse a single buffer for both.
14351454///
14361455/// 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 {
14381457 const w = windows ;
14391458
14401459 const access_mask = w .GENERIC_READ | w .SYNCHRONIZE ;
0 commit comments