| ... | ... | @@ -2381,7 +2381,7 @@ pub fn readlink(file_path: []const u8, out_buffer: []u8) ReadLinkError![]u8 { |
| 2381 | 2381 | @compileError("readlink is not supported in WASI; use readlinkat instead"); |
| 2382 | 2382 | } else if (builtin.os.tag == .windows) { |
| 2383 | 2383 | const file_path_w = try windows.sliceToPrefixedFileW(file_path); |
| 2384 | | return readlinkW(file_path_w.span(), out_buffer); |
| 2384 | return readlinkW(file_path_w.span().ptr, out_buffer); |
| 2385 | 2385 | } else { |
| 2386 | 2386 | const file_path_c = try toPosixPath(file_path); |
| 2387 | 2387 | return readlinkZ(&file_path_c, out_buffer); |
| ... | ... | @@ -2392,26 +2392,28 @@ pub const readlinkC = @compileError("deprecated: renamed to readlinkZ"); |
| 2392 | 2392 | |
| 2393 | 2393 | /// Windows-only. Same as `readlink` except `file_path` is null-terminated, WTF16 encoded. |
| 2394 | 2394 | /// See also `readlinkZ`. |
| 2395 | | pub fn readlinkW(file_path: []const u16, out_buffer: []u8) ReadLinkError![]u8 { |
| 2396 | | const handle = windows.ReadLink(file_path) catch |err| { |
| 2395 | pub fn readlinkW(file_path: [*:0]const u16, out_buffer: []u8) ReadLinkError![]u8 { |
| 2396 | const w = windows; |
| 2397 | const access_mode: w.DWORD = 0; |
| 2398 | const sharing = w.FILE_SHARE_DELETE | w.FILE_SHARE_READ | w.FILE_SHARE_WRITE; |
| 2399 | const disposition = w.OPEN_EXISTING; |
| 2400 | const flags = w.FILE_FLAG_BACKUP_SEMANTICS | w.FILE_FLAG_OPEN_REPARSE_POINT; |
| 2401 | const handle = w.CreateFileW(file_path, access_mode, sharing, null, disposition, flags, null) catch |err| { |
| 2397 | 2402 | switch (err) { |
| 2398 | | error.IsDir => unreachable, |
| 2399 | | error.NoDevice => return error.FileNotFound, |
| 2400 | 2403 | error.SharingViolation => return error.AccessDenied, |
| 2401 | | error.PipeBusy => unreachable, |
| 2402 | 2404 | error.PathAlreadyExists => unreachable, |
| 2403 | | error.WouldBlock => unreachable, |
| 2405 | error.PipeBusy => unreachable, |
| 2404 | 2406 | else => |e| return e, |
| 2405 | 2407 | } |
| 2406 | 2408 | }; |
| 2407 | | var reparse_buf: [windows.MAXIMUM_REPARSE_DATA_BUFFER_SIZE]u8 = undefined; |
| 2408 | | _ = try windows.DeviceIoControl(handle, windows.FSCTL_GET_REPARSE_POINT, null, reparse_buf[0..], null); |
| 2409 | | const reparse_struct = mem.bytesAsValue(windows._REPARSE_DATA_BUFFER, reparse_buf[0..@sizeOf(windows._REPARSE_DATA_BUFFER)]); |
| 2409 | var reparse_buf: [w.MAXIMUM_REPARSE_DATA_BUFFER_SIZE]u8 = undefined; |
| 2410 | _ = try w.DeviceIoControl(handle, w.FSCTL_GET_REPARSE_POINT, null, reparse_buf[0..], null); |
| 2411 | const reparse_struct = mem.bytesAsValue(w.REPARSE_DATA_BUFFER, reparse_buf[0..@sizeOf(w.REPARSE_DATA_BUFFER)]); |
| 2410 | 2412 | switch (reparse_struct.ReparseTag) { |
| 2411 | | windows.IO_REPARSE_TAG_SYMLINK => { |
| 2413 | w.IO_REPARSE_TAG_SYMLINK => { |
| 2412 | 2414 | std.debug.warn("got symlink!", .{}); |
| 2413 | 2415 | }, |
| 2414 | | windows.IO_REPARSE_TAG_MOUNT_POINT => { |
| 2416 | w.IO_REPARSE_TAG_MOUNT_POINT => { |
| 2415 | 2417 | std.debug.warn("got mount point!", .{}); |
| 2416 | 2418 | }, |
| 2417 | 2419 | else => |value| { |
| ... | ... | @@ -2426,7 +2428,7 @@ pub fn readlinkW(file_path: []const u16, out_buffer: []u8) ReadLinkError![]u8 { |
| 2426 | 2428 | pub fn readlinkZ(file_path: [*:0]const u8, out_buffer: []u8) ReadLinkError![]u8 { |
| 2427 | 2429 | if (builtin.os.tag == .windows) { |
| 2428 | 2430 | const file_path_w = try windows.cStrToPrefixedFileW(file_path); |
| 2429 | | return readlinkW(file_path_w.span(), out_buffer); |
| 2431 | return readlinkW(file_path_w.span().ptr, out_buffer); |
| 2430 | 2432 | } |
| 2431 | 2433 | const rc = system.readlink(file_path, out_buffer.ptr, out_buffer.len); |
| 2432 | 2434 | switch (errno(rc)) { |