[os2]: Split file type from mode bits

This commit is contained in:
flysand7
2024-07-18 23:09:27 +11:00
parent 0bb4cc6ce5
commit 7b501b22bb
13 changed files with 137 additions and 120 deletions
+6 -10
View File
@@ -12,14 +12,14 @@ _is_path_separator :: proc(c: byte) -> bool {
return c == '\\' || c == '/'
}
_mkdir :: proc(name: string, perm: File_Mode) -> Error {
_mkdir :: proc(name: string, perm: int) -> Error {
if !win32.CreateDirectoryW(_fix_long_path(name), nil) {
return _get_platform_error()
}
return nil
}
_mkdir_all :: proc(path: string, perm: File_Mode) -> Error {
_mkdir_all :: proc(path: string, perm: int) -> Error {
fix_root_directory :: proc(p: string) -> (s: string, allocated: bool, err: runtime.Allocator_Error) {
if len(p) == len(`\\?\c:`) {
if is_path_separator(p[0]) && is_path_separator(p[1]) && p[2] == '?' && is_path_separator(p[3]) && p[5] == ':' {
@@ -33,9 +33,9 @@ _mkdir_all :: proc(path: string, perm: File_Mode) -> Error {
TEMP_ALLOCATOR_GUARD()
dir, err := stat(path, temp_allocator())
dir_stat, err := stat(path, temp_allocator())
if err == nil {
if dir.is_directory {
if dir_stat.type == .Directory {
return nil
}
return .Exist
@@ -61,8 +61,8 @@ _mkdir_all :: proc(path: string, perm: File_Mode) -> Error {
err = mkdir(path, perm)
if err != nil {
dir1, err1 := lstat(path, temp_allocator())
if err1 == nil && dir1.is_directory {
new_dir_stat, err1 := lstat(path, temp_allocator())
if err1 == nil && new_dir_stat.type == .Directory {
return nil
}
return err
@@ -85,7 +85,6 @@ _setwd :: proc(dir: string) -> (err: Error) {
return nil
}
can_use_long_paths: bool
@(init)
@@ -96,7 +95,6 @@ init_long_path_support :: proc() {
can_use_long_paths = false
}
_fix_long_path_slice :: proc(path: string) -> []u16 {
return win32.utf8_to_utf16(_fix_long_path_internal(path))
}
@@ -105,7 +103,6 @@ _fix_long_path :: proc(path: string) -> win32.wstring {
return win32.utf8_to_wstring(_fix_long_path_internal(path))
}
_fix_long_path_internal :: proc(path: string) -> string {
if can_use_long_paths {
return path
@@ -162,5 +159,4 @@ _fix_long_path_internal :: proc(path: string) -> string {
}
return string(path_buf[:w])
}