| author | |
| committer | |
| log | a4310cf8b4f104802360cb854e2dcc48802301a6 |
| tree | 9835d055e7aee7923750a44bc881daf4e6f9a087 |
| parent | 7f56744320139ef134658f9ee756050345a31d30 |
2 files changed, 33 insertions(+), 1 deletions(-)
std/os/index.zig+29| ... | ... | @@ -577,6 +577,35 @@ pub fn atomicSymLink(allocator: &Allocator, existing_path: []const u8, new_path: |
| 577 | 577 | } |
| 578 | 578 | |
| 579 | 579 | pub fn deleteFile(allocator: &Allocator, file_path: []const u8) -> %void { |
| 580 | if (builtin.os == Os.windows) { | |
| 581 | return deleteFileWindows(allocator, file_path); | |
| 582 | } else { | |
| 583 | return deleteFilePosix(allocator, file_path); | |
| 584 | } | |
| 585 | } | |
| 586 | ||
| 587 | error FileNotFound; | |
| 588 | error AccessDenied; | |
| 589 | ||
| 590 | pub fn deleteFileWindows(allocator: &Allocator, file_path: []const u8) -> %void { | |
| 591 | const buf = %return allocator.alloc(u8, file_path.len + 1); | |
| 592 | defer allocator.free(buf); | |
| 593 | ||
| 594 | mem.copy(u8, buf, file_path); | |
| 595 | buf[file_path.len] = 0; | |
| 596 | ||
| 597 | if (!windows.DeleteFileA(buf.ptr)) { | |
| 598 | const err = windows.GetLastError(); | |
| 599 | return switch (err) { | |
| 600 | windows.ERROR.FILE_NOT_FOUND => error.FileNotFound, | |
| 601 | windows.ERROR.ACCESS_DENIED => error.AccessDenied, | |
| 602 | windows.ERROR.FILENAME_EXCED_RANGE, windows.ERROR.INVALID_PARAMETER => error.NameTooLong, | |
| 603 | else => error.Unexpected, | |
| 604 | } | |
| 605 | } | |
| 606 | } | |
| 607 | ||
| 608 | pub fn deleteFilePosix(allocator: &Allocator, file_path: []const u8) -> %void { | |
| 580 | 609 | const buf = %return allocator.alloc(u8, file_path.len + 1); |
| 581 | 610 | defer allocator.free(buf); |
| 582 | 611 |
std/os/windows/index.zig+4-1| ... | ... | @@ -7,13 +7,15 @@ pub extern "kernel32" stdcallcc fn CryptReleaseContext(hProv: HCRYPTPROV, dwFlag |
| 7 | 7 | |
| 8 | 8 | pub extern "kernel32" stdcallcc fn CryptGenRandom(hProv: HCRYPTPROV, dwLen: DWORD, pbBuffer: &BYTE) -> bool; |
| 9 | 9 | |
| 10 | pub extern "kernel32" stdcallcc fn DeleteFileA(lpFileName: LPCSTR) -> bool; | |
| 11 | ||
| 10 | 12 | pub extern "kernel32" stdcallcc fn ExitProcess(exit_code: UINT) -> noreturn; |
| 11 | 13 | |
| 12 | 14 | pub extern "kernel32" stdcallcc fn GetCommandLine() -> LPTSTR; |
| 13 | 15 | |
| 14 | 16 | pub extern "kernel32" stdcallcc fn GetConsoleMode(in_hConsoleHandle: HANDLE, out_lpMode: &DWORD) -> bool; |
| 15 | 17 | |
| 16 | pub extern "kernel32" stdcallcc fn GetCurrentDirectoryA(nBufferLength: WORD, lpBuffer: ?LPTSTR) -> DWORD; | |
| 18 | pub extern "kernel32" stdcallcc fn GetCurrentDirectoryA(nBufferLength: WORD, lpBuffer: ?LPSTR) -> DWORD; | |
| 17 | 19 | |
| 18 | 20 | /// Retrieves the calling thread's last-error code value. The last-error code is maintained on a per-thread basis. |
| 19 | 21 | /// Multiple threads do not overwrite each other's last-error code. |
| ... | ... | @@ -68,6 +70,7 @@ pub const HANDLE = &c_void; |
| 68 | 70 | pub const HINSTANCE = &@OpaqueType(); |
| 69 | 71 | pub const HCRYPTPROV = ULONG_PTR; |
| 70 | 72 | pub const LPCTSTR = &const TCHAR; |
| 73 | pub const LPCSTR = &const CHAR; | |
| 71 | 74 | pub const LPDWORD = &DWORD; |
| 72 | 75 | pub const LPVOID = &c_void; |
| 73 | 76 | pub const PVOID = &c_void; |