| ... | @@ -2355,6 +2355,8 @@ pub const ReadLinkError = error{ | ... | @@ -2355,6 +2355,8 @@ pub const ReadLinkError = error{ |
| 2355 | FileNotFound, | 2355 | FileNotFound, |
| 2356 | SystemResources, | 2356 | SystemResources, |
| 2357 | NotDir, | 2357 | NotDir, |
| | 2358 | /// Windows-only. |
| | 2359 | UnsupportedSymlinkType, |
| 2358 | } || UnexpectedError; | 2360 | } || UnexpectedError; |
| 2359 | | 2361 | |
| 2360 | /// Read value of a symbolic link. | 2362 | /// Read value of a symbolic link. |
| ... | @@ -2373,9 +2375,35 @@ pub fn readlink(file_path: []const u8, out_buffer: []u8) ReadLinkError![]u8 { | ... | @@ -2373,9 +2375,35 @@ pub fn readlink(file_path: []const u8, out_buffer: []u8) ReadLinkError![]u8 { |
| 2373 | | 2375 | |
| 2374 | pub const readlinkC = @compileError("deprecated: renamed to readlinkZ"); | 2376 | pub const readlinkC = @compileError("deprecated: renamed to readlinkZ"); |
| 2375 | | 2377 | |
| 2376 | /// Windows-only. Same as `readlink` expecte `file_path` is null-terminated, WTF16 encoded. | 2378 | /// Windows-only. Same as `readlink` except `file_path` is null-terminated, WTF16 encoded. |
| 2377 | /// Seel also `readlinkZ`. | 2379 | /// See also `readlinkZ`. |
| 2378 | pub fn readlinkW(file_path: [*:0]const u16, out_buffer: []u8) ReadLinkError![]u8 { | 2380 | pub fn readlinkW(file_path: [*:0]const u16, out_buffer: []u8) ReadLinkError![]u8 { |
| | 2381 | const handle = windows.OpenFile(file_path, .{ |
| | 2382 | .access_mask = 0, |
| | 2383 | .creation = c.FILE_OPEN_REPARSE_POINT | c.FILE_LIST_DIRECTORY, |
| | 2384 | .io_mode = 0, |
| | 2385 | }) catch |err| { |
| | 2386 | switch (err) { |
| | 2387 | error.IsDir => unreachable, |
| | 2388 | error.NoDevice => return error.FileNotFound, |
| | 2389 | error.SharingViolation => return error.AccessDenied, |
| | 2390 | error.PipeBusy => unreachable, |
| | 2391 | error.PathAlreadyExists => unreachable, |
| | 2392 | error.WouldBlock => unreachable, |
| | 2393 | else => return err, |
| | 2394 | } |
| | 2395 | }; |
| | 2396 | var reparse_buf: [windows.MAXIMUM_REPARSE_DATA_BUFFER_SIZE]u8 = undefined; |
| | 2397 | _ = try windows.DeviceIoControl(handle, windows.FSCTL_GET_REPARSE_POINT, null, reparse_buf[0..], null); |
| | 2398 | const reparse_struct = @bitCast(windows._REPARSE_DATA_BUFFER, reparse_buf[0..@sizeOf(windows._REPARSE_DATA_BUFFER)]); |
| | 2399 | switch (reparse_struct.ReparseTag) { |
| | 2400 | windows.IO_REPARSE_TAG_SYMLINK => {}, |
| | 2401 | windows.IO_REPARSE_TAG_MOUNT_POINT => {}, |
| | 2402 | else => |value| { |
| | 2403 | std.debug.print("unsupported symlink type: {}", value); |
| | 2404 | return error.UnsupportedSymlinkType; |
| | 2405 | }, |
| | 2406 | } |
| 2379 | @compileError("TODO implement readlink for Windows"); | 2407 | @compileError("TODO implement readlink for Windows"); |
| 2380 | } | 2408 | } |
| 2381 | | 2409 | |