| ... | ... | @@ -761,11 +761,30 @@ pub fn rename(allocator: &Allocator, old_path: []const u8, new_path: []const u8) |
| 761 | 761 | } |
| 762 | 762 | |
| 763 | 763 | pub fn makeDir(allocator: &Allocator, dir_path: []const u8) -> %void { |
| 764 | | const path_buf = %return allocator.alloc(u8, dir_path.len + 1); |
| 764 | if (is_windows) { |
| 765 | return makeDirWindows(allocator, dir_path); |
| 766 | } else { |
| 767 | return makeDirPosix(allocator, dir_path); |
| 768 | } |
| 769 | } |
| 770 | |
| 771 | pub fn makeDirWindows(allocator: &Allocator, dir_path: []const u8) -> %void { |
| 772 | const path_buf = %return cstr.addNullByte(allocator, dir_path); |
| 765 | 773 | defer allocator.free(path_buf); |
| 766 | 774 | |
| 767 | | mem.copy(u8, path_buf, dir_path); |
| 768 | | path_buf[dir_path.len] = 0; |
| 775 | if (!windows.CreateDirectoryA(path_buf.ptr, null)) { |
| 776 | const err = windows.GetLastError(); |
| 777 | return switch (err) { |
| 778 | windows.ERROR.ALREADY_EXISTS => error.PathAlreadyExists, |
| 779 | windows.ERROR.PATH_NOT_FOUND => error.FileNotFound, |
| 780 | else => error.Unexpected, |
| 781 | }; |
| 782 | } |
| 783 | } |
| 784 | |
| 785 | pub fn makeDirPosix(allocator: &Allocator, dir_path: []const u8) -> %void { |
| 786 | const path_buf = cstr.addNullByte(allocator, dir_path); |
| 787 | defer allocator.free(path_buf); |
| 769 | 788 | |
| 770 | 789 | const err = posix.getErrno(posix.mkdir(path_buf.ptr, 0o755)); |
| 771 | 790 | if (err > 0) { |