mirror of
https://github.com/ziglang/zig.git
synced 2025-12-20 13:13:16 +00:00
implement os.makeDir for windows
This commit is contained in:
parent
8d3eaab871
commit
0bc80411f6
@ -761,11 +761,30 @@ pub fn rename(allocator: &Allocator, old_path: []const u8, new_path: []const u8)
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn makeDir(allocator: &Allocator, dir_path: []const u8) -> %void {
|
pub fn makeDir(allocator: &Allocator, dir_path: []const u8) -> %void {
|
||||||
const path_buf = %return allocator.alloc(u8, dir_path.len + 1);
|
if (is_windows) {
|
||||||
|
return makeDirWindows(allocator, dir_path);
|
||||||
|
} else {
|
||||||
|
return makeDirPosix(allocator, dir_path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn makeDirWindows(allocator: &Allocator, dir_path: []const u8) -> %void {
|
||||||
|
const path_buf = %return cstr.addNullByte(allocator, dir_path);
|
||||||
defer allocator.free(path_buf);
|
defer allocator.free(path_buf);
|
||||||
|
|
||||||
mem.copy(u8, path_buf, dir_path);
|
if (!windows.CreateDirectoryA(path_buf.ptr, null)) {
|
||||||
path_buf[dir_path.len] = 0;
|
const err = windows.GetLastError();
|
||||||
|
return switch (err) {
|
||||||
|
windows.ERROR.ALREADY_EXISTS => error.PathAlreadyExists,
|
||||||
|
windows.ERROR.PATH_NOT_FOUND => error.FileNotFound,
|
||||||
|
else => error.Unexpected,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn makeDirPosix(allocator: &Allocator, dir_path: []const u8) -> %void {
|
||||||
|
const path_buf = cstr.addNullByte(allocator, dir_path);
|
||||||
|
defer allocator.free(path_buf);
|
||||||
|
|
||||||
const err = posix.getErrno(posix.mkdir(path_buf.ptr, 0o755));
|
const err = posix.getErrno(posix.mkdir(path_buf.ptr, 0o755));
|
||||||
if (err > 0) {
|
if (err > 0) {
|
||||||
|
|||||||
@ -10,6 +10,9 @@ pub extern "advapi32" stdcallcc fn CryptGenRandom(hProv: HCRYPTPROV, dwLen: DWOR
|
|||||||
|
|
||||||
pub extern "kernel32" stdcallcc fn CloseHandle(hObject: HANDLE) -> BOOL;
|
pub extern "kernel32" stdcallcc fn CloseHandle(hObject: HANDLE) -> BOOL;
|
||||||
|
|
||||||
|
pub extern "kernel32" stdcallcc fn CreateDirectoryA(lpPathName: LPCSTR,
|
||||||
|
lpSecurityAttributes: ?&SECURITY_ATTRIBUTES) -> BOOL;
|
||||||
|
|
||||||
pub extern "kernel32" stdcallcc fn CreateFileA(lpFileName: LPCSTR, dwDesiredAccess: DWORD,
|
pub extern "kernel32" stdcallcc fn CreateFileA(lpFileName: LPCSTR, dwDesiredAccess: DWORD,
|
||||||
dwShareMode: DWORD, lpSecurityAttributes: ?LPSECURITY_ATTRIBUTES, dwCreationDisposition: DWORD,
|
dwShareMode: DWORD, lpSecurityAttributes: ?LPSECURITY_ATTRIBUTES, dwCreationDisposition: DWORD,
|
||||||
dwFlagsAndAttributes: DWORD, hTemplateFile: ?HANDLE) -> HANDLE;
|
dwFlagsAndAttributes: DWORD, hTemplateFile: ?HANDLE) -> HANDLE;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user