@@ -1284,7 +1284,7 @@ pub fn realpath(self: Dir, pathname: []const u8, out_buffer: []u8) RealPathError
1284
1284
if (native_os == .windows ) {
1285
1285
var pathname_w = try windows .sliceToPrefixedFileW (self .fd , pathname );
1286
1286
1287
- const wide_slice = try self .realpathW (pathname_w .span (), & pathname_w .data );
1287
+ const wide_slice = try self .realpathW2 (pathname_w .span (), & pathname_w .data );
1288
1288
1289
1289
const len = std .unicode .calcWtf8Len (wide_slice );
1290
1290
if (len > out_buffer .len )
@@ -1303,7 +1303,7 @@ pub fn realpathZ(self: Dir, pathname: [*:0]const u8, out_buffer: []u8) RealPathE
1303
1303
if (native_os == .windows ) {
1304
1304
var pathname_w = try windows .cStrToPrefixedFileW (self .fd , pathname );
1305
1305
1306
- const wide_slice = try self .realpathW (pathname_w .span (), & pathname_w .data );
1306
+ const wide_slice = try self .realpathW2 (pathname_w .span (), & pathname_w .data );
1307
1307
1308
1308
const len = std .unicode .calcWtf8Len (wide_slice );
1309
1309
if (len > out_buffer .len )
@@ -1339,6 +1339,25 @@ pub fn realpathZ(self: Dir, pathname: [*:0]const u8, out_buffer: []u8) RealPathE
1339
1339
return result ;
1340
1340
}
1341
1341
1342
+ /// Deprecated: use `realpathW2`.
1343
+ ///
1344
+ /// Windows-only. Same as `Dir.realpath` except `pathname` is WTF16 LE encoded.
1345
+ /// The result is encoded as [WTF-8](https://simonsapin.github.io/wtf-8/).
1346
+ /// See also `Dir.realpath`, `realpathW`.
1347
+ pub fn realpathW (self : Dir , pathname : []const u16 , out_buffer : []u8 ) RealPathError ! []u8 {
1348
+ var wide_buf : [std .os .windows .PATH_MAX_WIDE ]u16 = undefined ;
1349
+
1350
+ const wide_slice = try self .realpathW2 (pathname , & wide_buf );
1351
+
1352
+ var big_out_buf : [fs .max_path_bytes ]u8 = undefined ;
1353
+ const end_index = std .unicode .wtf16LeToWtf8 (& big_out_buf , wide_slice );
1354
+ if (end_index > out_buffer .len )
1355
+ return error .NameTooLong ;
1356
+ const result = out_buffer [0.. end_index ];
1357
+ @memcpy (result , big_out_buf [0.. end_index ]);
1358
+ return result ;
1359
+ }
1360
+
1342
1361
/// Windows-only. Same as `Dir.realpath` except
1343
1362
/// * `pathname` and the result are WTF-16 LE encoded
1344
1363
/// * `pathname` is relative or has the NT namespace prefix. See `windows.wToPrefixedFileW` for details.
@@ -1347,7 +1366,7 @@ pub fn realpathZ(self: Dir, pathname: [*:0]const u8, out_buffer: []u8) RealPathE
1347
1366
/// is safe to reuse a single buffer for both.
1348
1367
///
1349
1368
/// See also `Dir.realpath`, `realpathW`.
1350
- pub fn realpathW (self : Dir , pathname : []const u16 , out_buffer : []u16 ) RealPathError ! []u16 {
1369
+ pub fn realpathW2 (self : Dir , pathname : []const u16 , out_buffer : []u16 ) RealPathError ! []u16 {
1351
1370
const w = windows ;
1352
1371
1353
1372
const access_mask = w .GENERIC_READ | w .SYNCHRONIZE ;
0 commit comments