@@ -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 ;
0 commit comments