From ee876ad66b77db7d3f4265c6026ae87448b794df Mon Sep 17 00:00:00 2001 From: gingerBill Date: Sun, 19 Sep 2021 11:59:44 +0100 Subject: [PATCH] Strip semicolons --- core/os/os2/env.odin | 14 +- core/os/os2/env_windows.odin | 56 +++--- core/os/os2/errors.odin | 64 +++--- core/os/os2/errors_windows.odin | 6 +- core/os/os2/file.odin | 94 ++++----- core/os/os2/file_stream.odin | 98 +++++----- core/os/os2/file_util.odin | 102 +++++----- core/os/os2/file_windows.odin | 58 +++--- core/os/os2/heap.odin | 6 +- core/os/os2/heap_windows.odin | 68 +++---- core/os/os2/path.odin | 16 +- core/os/os2/path_windows.odin | 16 +- core/os/os2/pipe.odin | 2 +- core/os/os2/pipe_windows.odin | 6 +- core/os/os2/process.odin | 37 ++-- core/os/os2/stat.odin | 14 +- core/os/os2/stat_windows.odin | 304 +++++++++++++++-------------- core/os/os2/temp_file.odin | 6 +- core/os/os2/temp_file_windows.odin | 16 +- core/os/os2/user.odin | 48 ++--- 20 files changed, 517 insertions(+), 514 deletions(-) diff --git a/core/os/os2/env.odin b/core/os/os2/env.odin index ae1752a10..f25290a59 100644 --- a/core/os/os2/env.odin +++ b/core/os/os2/env.odin @@ -5,8 +5,8 @@ package os2 // To distinguish between an empty value and an unset value, use lookup_env // NOTE: the value will be allocated with the supplied allocator get_env :: proc(key: string, allocator := context.allocator) -> string { - value, _ := lookup_env(key, allocator); - return value; + value, _ := lookup_env(key, allocator) + return value } // lookup_env gets the value of the environment variable named by the key @@ -14,30 +14,30 @@ get_env :: proc(key: string, allocator := context.allocator) -> string { // Otherwise the returned value will be empty and the boolean will be false // NOTE: the value will be allocated with the supplied allocator lookup_env :: proc(key: string, allocator := context.allocator) -> (value: string, found: bool) { - return _lookup_env(key, allocator); + return _lookup_env(key, allocator) } // set_env sets the value of the environment variable named by the key // Returns true on success, false on failure set_env :: proc(key, value: string) -> bool { - return _set_env(key, value); + return _set_env(key, value) } // unset_env unsets a single environment variable // Returns true on success, false on failure unset_env :: proc(key: string) -> bool { - return _unset_env(key); + return _unset_env(key) } clear_env :: proc() { - _clear_env(); + _clear_env() } // environ returns a copy of strings representing the environment, in the form "key=value" // NOTE: the slice of strings and the strings with be allocated using the supplied allocator environ :: proc(allocator := context.allocator) -> []string { - return _environ(allocator); + return _environ(allocator) } diff --git a/core/os/os2/env_windows.odin b/core/os/os2/env_windows.odin index b6a73ad81..af04db858 100644 --- a/core/os/os2/env_windows.odin +++ b/core/os/os2/env_windows.odin @@ -6,75 +6,75 @@ import win32 "core:sys/windows" _lookup_env :: proc(key: string, allocator := context.allocator) -> (value: string, found: bool) { if key == "" { - return; + return } - wkey := win32.utf8_to_wstring(key); - b := make([dynamic]u16, 100, context.temp_allocator); + wkey := win32.utf8_to_wstring(key) + b := make([dynamic]u16, 100, context.temp_allocator) for { - n := win32.GetEnvironmentVariableW(wkey, raw_data(b), u32(len(b))); + n := win32.GetEnvironmentVariableW(wkey, raw_data(b), u32(len(b))) if n == 0 { - err := win32.GetLastError(); + err := win32.GetLastError() if err == win32.ERROR_ENVVAR_NOT_FOUND { - return "", false; + return "", false } } if n <= u32(len(b)) { - value = win32.utf16_to_utf8(b[:n], allocator); - found = true; - return; + value = win32.utf16_to_utf8(b[:n], allocator) + found = true + return } - resize(&b, len(b)*2); + resize(&b, len(b)*2) } } _set_env :: proc(key, value: string) -> bool { - k := win32.utf8_to_wstring(key); - v := win32.utf8_to_wstring(value); + k := win32.utf8_to_wstring(key) + v := win32.utf8_to_wstring(value) - return bool(win32.SetEnvironmentVariableW(k, v)); + return bool(win32.SetEnvironmentVariableW(k, v)) } _unset_env :: proc(key: string) -> bool { - k := win32.utf8_to_wstring(key); - return bool(win32.SetEnvironmentVariableW(k, nil)); + k := win32.utf8_to_wstring(key) + return bool(win32.SetEnvironmentVariableW(k, nil)) } _clear_env :: proc() { - envs := environ(context.temp_allocator); + envs := environ(context.temp_allocator) for env in envs { for j in 1.. (n: int, err: Error) { - s := transmute([]byte)mem.Raw_Slice{data, len}; - return write(fd, s); + s := transmute([]byte)mem.Raw_Slice{data, len} + return write(fd, s) } read_ptr :: proc(fd: Handle, data: rawptr, len: int) -> (n: int, err: Error) { - s := transmute([]byte)mem.Raw_Slice{data, len}; - return read(fd, s); + s := transmute([]byte)mem.Raw_Slice{data, len} + return read(fd, s) } read_entire_file :: proc(name: string, allocator := context.allocator) -> ([]byte, Error) { - f, ferr := open(name); + f, ferr := open(name) if ferr != nil { - return nil, ferr; + return nil, ferr } - defer close(f); + defer close(f) - size: int; + size: int if size64, err := file_size(f); err == nil { if i64(int(size64)) != size64 { - size = int(size64); + size = int(size64) } } - size += 1; // for EOF + size += 1 // for EOF // TODO(bill): Is this correct logic? - total: int; - data := make([]byte, size, allocator); + total: int + data := make([]byte, size, allocator) for { - n, err := read(f, data[total:]); - total += n; + n, err := read(f, data[total:]) + total += n if err != nil { if err == .EOF { - err = nil; + err = nil } - return data[:total], err; + return data[:total], err } } } write_entire_file :: proc(name: string, data: []byte, perm: File_Mode, truncate := true) -> Error { - flags := O_WRONLY|O_CREATE; + flags := O_WRONLY|O_CREATE if truncate { - flags |= O_TRUNC; + flags |= O_TRUNC } - f, err := open_file(name, flags, perm); + f, err := open_file(name, flags, perm) if err != nil { - return err; + return err } - _, err = write(f, data); + _, err = write(f, data) if cerr := close(f); cerr != nil && err == nil { - err = cerr; + err = cerr } - return err; + return err } diff --git a/core/os/os2/file_windows.odin b/core/os/os2/file_windows.odin index 5e87d80a4..cfc9feebf 100644 --- a/core/os/os2/file_windows.odin +++ b/core/os/os2/file_windows.odin @@ -5,125 +5,125 @@ import "core:io" import "core:time" _create :: proc(name: string) -> (Handle, Error) { - return 0, nil; + return 0, nil } _open :: proc(name: string) -> (Handle, Error) { - return 0, nil; + return 0, nil } _open_file :: proc(name: string, flag: int, perm: File_Mode) -> (Handle, Error) { - return 0, nil; + return 0, nil } _close :: proc(fd: Handle) -> Error { - return nil; + return nil } _name :: proc(fd: Handle, allocator := context.allocator) -> string { - return ""; + return "" } _seek :: proc(fd: Handle, offset: i64, whence: Seek_From) -> (ret: i64, err: Error) { - return; + return } _read :: proc(fd: Handle, p: []byte) -> (n: int, err: Error) { - return; + return } _read_at :: proc(fd: Handle, p: []byte, offset: i64) -> (n: int, err: Error) { - return; + return } _read_from :: proc(fd: Handle, r: io.Reader) -> (n: i64, err: Error) { - return; + return } _write :: proc(fd: Handle, p: []byte) -> (n: int, err: Error) { - return; + return } _write_at :: proc(fd: Handle, p: []byte, offset: i64) -> (n: int, err: Error) { - return; + return } _write_to :: proc(fd: Handle, w: io.Writer) -> (n: i64, err: Error) { - return; + return } _file_size :: proc(fd: Handle) -> (n: i64, err: Error) { - return; + return } _sync :: proc(fd: Handle) -> Error { - return nil; + return nil } _flush :: proc(fd: Handle) -> Error { - return nil; + return nil } _truncate :: proc(fd: Handle, size: i64) -> Maybe(Path_Error) { - return nil; + return nil } _remove :: proc(name: string) -> Maybe(Path_Error) { - return nil; + return nil } _rename :: proc(old_path, new_path: string) -> Maybe(Path_Error) { - return nil; + return nil } _link :: proc(old_name, new_name: string) -> Maybe(Link_Error) { - return nil; + return nil } _symlink :: proc(old_name, new_name: string) -> Maybe(Link_Error) { - return nil; + return nil } _read_link :: proc(name: string) -> (string, Maybe(Path_Error)) { - return "", nil; + return "", nil } _chdir :: proc(fd: Handle) -> Error { - return nil; + return nil } _chmod :: proc(fd: Handle, mode: File_Mode) -> Error { - return nil; + return nil } _chown :: proc(fd: Handle, uid, gid: int) -> Error { - return nil; + return nil } _lchown :: proc(name: string, uid, gid: int) -> Error { - return nil; + return nil } _chtimes :: proc(name: string, atime, mtime: time.Time) -> Maybe(Path_Error) { - return nil; + return nil } _exists :: proc(path: string) -> bool { - return false; + return false } _is_file :: proc(path: string) -> bool { - return false; + return false } _is_dir :: proc(path: string) -> bool { - return false; + return false } diff --git a/core/os/os2/heap.odin b/core/os/os2/heap.odin index aa1384442..92b5a9928 100644 --- a/core/os/os2/heap.odin +++ b/core/os/os2/heap.odin @@ -6,16 +6,16 @@ heap_allocator :: proc() -> runtime.Allocator { return runtime.Allocator{ procedure = heap_allocator_proc, data = nil, - }; + } } heap_allocator_proc :: proc(allocator_data: rawptr, mode: runtime.Allocator_Mode, size, alignment: int, old_memory: rawptr, old_size: int, loc := #caller_location) -> ([]byte, runtime.Allocator_Error) { - return _heap_allocator_proc(allocator_data, mode, size, alignment, old_memory, old_size, loc); + return _heap_allocator_proc(allocator_data, mode, size, alignment, old_memory, old_size, loc) } @(private) -error_allocator := heap_allocator; +error_allocator := heap_allocator diff --git a/core/os/os2/heap_windows.odin b/core/os/os2/heap_windows.odin index 25fe660ee..a719e4c88 100644 --- a/core/os/os2/heap_windows.odin +++ b/core/os/os2/heap_windows.odin @@ -6,25 +6,25 @@ import "core:mem" import win32 "core:sys/windows" heap_alloc :: proc(size: int) -> rawptr { - return win32.HeapAlloc(win32.GetProcessHeap(), win32.HEAP_ZERO_MEMORY, uint(size)); + return win32.HeapAlloc(win32.GetProcessHeap(), win32.HEAP_ZERO_MEMORY, uint(size)) } heap_resize :: proc(ptr: rawptr, new_size: int) -> rawptr { if new_size == 0 { - heap_free(ptr); - return nil; + heap_free(ptr) + return nil } if ptr == nil { - return heap_alloc(new_size); + return heap_alloc(new_size) } - return win32.HeapReAlloc(win32.GetProcessHeap(), win32.HEAP_ZERO_MEMORY, ptr, uint(new_size)); + return win32.HeapReAlloc(win32.GetProcessHeap(), win32.HEAP_ZERO_MEMORY, ptr, uint(new_size)) } heap_free :: proc(ptr: rawptr) { if ptr == nil { - return; + return } - win32.HeapFree(win32.GetProcessHeap(), 0, ptr); + win32.HeapFree(win32.GetProcessHeap(), 0, ptr) } _heap_allocator_proc :: proc(allocator_data: rawptr, mode: mem.Allocator_Mode, @@ -38,70 +38,70 @@ _heap_allocator_proc :: proc(allocator_data: rawptr, mode: mem.Allocator_Mode, // aligned_alloc :: proc(size, alignment: int, old_ptr: rawptr = nil) -> ([]byte, mem.Allocator_Error) { - a := max(alignment, align_of(rawptr)); - space := size + a - 1; + a := max(alignment, align_of(rawptr)) + space := size + a - 1 - allocated_mem: rawptr; + allocated_mem: rawptr if old_ptr != nil { - original_old_ptr := mem.ptr_offset((^rawptr)(old_ptr), -1)^; - allocated_mem = heap_resize(original_old_ptr, space+size_of(rawptr)); + original_old_ptr := mem.ptr_offset((^rawptr)(old_ptr), -1)^ + allocated_mem = heap_resize(original_old_ptr, space+size_of(rawptr)) } else { - allocated_mem = heap_alloc(space+size_of(rawptr)); + allocated_mem = heap_alloc(space+size_of(rawptr)) } - aligned_mem := rawptr(mem.ptr_offset((^u8)(allocated_mem), size_of(rawptr))); + aligned_mem := rawptr(mem.ptr_offset((^u8)(allocated_mem), size_of(rawptr))) - ptr := uintptr(aligned_mem); - aligned_ptr := (ptr - 1 + uintptr(a)) & -uintptr(a); - diff := int(aligned_ptr - ptr); + ptr := uintptr(aligned_mem) + aligned_ptr := (ptr - 1 + uintptr(a)) & -uintptr(a) + diff := int(aligned_ptr - ptr) if (size + diff) > space { - return nil, .Out_Of_Memory; + return nil, .Out_Of_Memory } - aligned_mem = rawptr(aligned_ptr); - mem.ptr_offset((^rawptr)(aligned_mem), -1)^ = allocated_mem; + aligned_mem = rawptr(aligned_ptr) + mem.ptr_offset((^rawptr)(aligned_mem), -1)^ = allocated_mem - return mem.byte_slice(aligned_mem, size), nil; + return mem.byte_slice(aligned_mem, size), nil } aligned_free :: proc(p: rawptr) { if p != nil { - heap_free(mem.ptr_offset((^rawptr)(p), -1)^); + heap_free(mem.ptr_offset((^rawptr)(p), -1)^) } } aligned_resize :: proc(p: rawptr, old_size: int, new_size: int, new_alignment: int) -> ([]byte, mem.Allocator_Error) { if p == nil { - return nil, nil; + return nil, nil } - return aligned_alloc(new_size, new_alignment, p); + return aligned_alloc(new_size, new_alignment, p) } switch mode { case .Alloc: - return aligned_alloc(size, alignment); + return aligned_alloc(size, alignment) case .Free: - aligned_free(old_memory); + aligned_free(old_memory) case .Free_All: - return nil, .Mode_Not_Implemented; + return nil, .Mode_Not_Implemented case .Resize: if old_memory == nil { - return aligned_alloc(size, alignment); + return aligned_alloc(size, alignment) } - return aligned_resize(old_memory, old_size, size, alignment); + return aligned_resize(old_memory, old_size, size, alignment) case .Query_Features: - set := (^mem.Allocator_Mode_Set)(old_memory); + set := (^mem.Allocator_Mode_Set)(old_memory) if set != nil { - set^ = {.Alloc, .Free, .Resize, .Query_Features}; + set^ = {.Alloc, .Free, .Resize, .Query_Features} } - return nil, nil; + return nil, nil case .Query_Info: - return nil, nil; + return nil, nil } - return nil, nil; + return nil, nil } diff --git a/core/os/os2/path.odin b/core/os/os2/path.odin index eee2b3cee..ee7d6e6f2 100644 --- a/core/os/os2/path.odin +++ b/core/os/os2/path.odin @@ -1,29 +1,29 @@ package os2 -Path_Separator :: _Path_Separator; // OS-Specific -Path_List_Separator :: _Path_List_Separator; // OS-Specific +Path_Separator :: _Path_Separator // OS-Specific +Path_List_Separator :: _Path_List_Separator // OS-Specific is_path_separator :: proc(c: byte) -> bool { - return _is_path_separator(c); + return _is_path_separator(c) } mkdir :: proc(name: string, perm: File_Mode) -> Maybe(Path_Error) { - return _mkdir(name, perm); + return _mkdir(name, perm) } mkdir_all :: proc(path: string, perm: File_Mode) -> Maybe(Path_Error) { - return _mkdir_all(path, perm); + return _mkdir_all(path, perm) } remove_all :: proc(path: string) -> Maybe(Path_Error) { - return _remove_all(path); + return _remove_all(path) } getwd :: proc(allocator := context.allocator) -> (dir: string, err: Error) { - return _getwd(allocator); + return _getwd(allocator) } setwd :: proc(dir: string) -> (err: Error) { - return _setwd(dir); + return _setwd(dir) } diff --git a/core/os/os2/path_windows.odin b/core/os/os2/path_windows.odin index 5056eb638..607f56968 100644 --- a/core/os/os2/path_windows.odin +++ b/core/os/os2/path_windows.odin @@ -1,31 +1,31 @@ //+private package os2 -_Path_Separator :: '\\'; -_Path_List_Separator :: ';'; +_Path_Separator :: '\\' +_Path_List_Separator :: ';' _is_path_separator :: proc(c: byte) -> bool { - return c == '\\' || c == '/'; + return c == '\\' || c == '/' } _mkdir :: proc(name: string, perm: File_Mode) -> Maybe(Path_Error) { - return nil; + return nil } _mkdir_all :: proc(path: string, perm: File_Mode) -> Maybe(Path_Error) { // TODO(bill): _mkdir_all for windows - return nil; + return nil } _remove_all :: proc(path: string) -> Maybe(Path_Error) { // TODO(bill): _remove_all for windows - return nil; + return nil } _getwd :: proc(allocator := context.allocator) -> (dir: string, err: Error) { - return "", nil; + return "", nil } _setwd :: proc(dir: string) -> (err: Error) { - return nil; + return nil } diff --git a/core/os/os2/pipe.odin b/core/os/os2/pipe.odin index 8bb46b303..c38f03f03 100644 --- a/core/os/os2/pipe.odin +++ b/core/os/os2/pipe.odin @@ -1,5 +1,5 @@ package os2 pipe :: proc() -> (r, w: Handle, err: Error) { - return _pipe(); + return _pipe() } diff --git a/core/os/os2/pipe_windows.odin b/core/os/os2/pipe_windows.odin index 04750bf88..5570ca282 100644 --- a/core/os/os2/pipe_windows.odin +++ b/core/os/os2/pipe_windows.odin @@ -4,10 +4,10 @@ package os2 import win32 "core:sys/windows" _pipe :: proc() -> (r, w: Handle, err: Error) { - p: [2]win32.HANDLE; + p: [2]win32.HANDLE if !win32.CreatePipe(&p[0], &p[1], nil, 0) { - return 0, 0, Platform_Error{i32(win32.GetLastError())}; + return 0, 0, Platform_Error{i32(win32.GetLastError())} } - return Handle(p[0]), Handle(p[1]), nil; + return Handle(p[0]), Handle(p[1]), nil } diff --git a/core/os/os2/process.odin b/core/os/os2/process.odin index f0060b54f..028951fe3 100644 --- a/core/os/os2/process.odin +++ b/core/os/os2/process.odin @@ -2,35 +2,36 @@ package os2 import sync "core:sync/sync2" import "core:time" +import "core:runtime" -args: []string; +args: []string exit :: proc "contextless" (code: int) -> ! { - // + runtime.trap() } get_uid :: proc() -> int { - return -1; + return -1 } get_euid :: proc() -> int { - return -1; + return -1 } get_gid :: proc() -> int { - return -1; + return -1 } get_egid :: proc() -> int { - return -1; + return -1 } get_pid :: proc() -> int { - return -1; + return -1 } get_ppid :: proc() -> int { - return -1; + return -1 } @@ -49,7 +50,7 @@ Process_Attributes :: struct { sys: ^Process_Attributes_OS_Specific, } -Process_Attributes_OS_Specific :: struct{}; +Process_Attributes_OS_Specific :: struct{} Process_Error :: enum { None, @@ -65,35 +66,35 @@ Process_State :: struct { sys: rawptr, } -Signal :: #type proc(); +Signal :: #type proc() -Kill: Signal = nil; -Interrupt: Signal = nil; +Kill: Signal = nil +Interrupt: Signal = nil find_process :: proc(pid: int) -> (^Process, Process_Error) { - return nil, .None; + return nil, .None } process_start :: proc(name: string, argv: []string, attr: ^Process_Attributes) -> (^Process, Process_Error) { - return nil, .None; + return nil, .None } process_release :: proc(p: ^Process) -> Process_Error { - return .None; + return .None } process_kill :: proc(p: ^Process) -> Process_Error { - return .None; + return .None } process_signal :: proc(p: ^Process, sig: Signal) -> Process_Error { - return .None; + return .None } process_wait :: proc(p: ^Process) -> (Process_State, Process_Error) { - return {}, .None; + return {}, .None } diff --git a/core/os/os2/stat.odin b/core/os/os2/stat.odin index 791948c8d..19f1453ff 100644 --- a/core/os/os2/stat.odin +++ b/core/os/os2/stat.odin @@ -15,28 +15,28 @@ File_Info :: struct { file_info_slice_delete :: proc(infos: []File_Info, allocator := context.allocator) { for i := len(infos)-1; i >= 0; i -= 1 { - file_info_delete(infos[i], allocator); + file_info_delete(infos[i], allocator) } - delete(infos, allocator); + delete(infos, allocator) } file_info_delete :: proc(fi: File_Info, allocator := context.allocator) { - delete(fi.fullpath, allocator); + delete(fi.fullpath, allocator) } fstat :: proc(fd: Handle, allocator := context.allocator) -> (File_Info, Maybe(Path_Error)) { - return _fstat(fd, allocator); + return _fstat(fd, allocator) } stat :: proc(name: string, allocator := context.allocator) -> (File_Info, Maybe(Path_Error)) { - return _stat(name, allocator); + return _stat(name, allocator) } lstat :: proc(name: string, allocator := context.allocator) -> (File_Info, Maybe(Path_Error)) { - return _lstat(name, allocator); + return _lstat(name, allocator) } same_file :: proc(fi1, fi2: File_Info) -> bool { - return _same_file(fi1, fi2); + return _same_file(fi1, fi2) } diff --git a/core/os/os2/stat_windows.odin b/core/os/os2/stat_windows.odin index 0b6834fe0..f46a9435c 100644 --- a/core/os/os2/stat_windows.odin +++ b/core/os/os2/stat_windows.odin @@ -6,368 +6,370 @@ import win32 "core:sys/windows" _fstat :: proc(fd: Handle, allocator := context.allocator) -> (File_Info, Maybe(Path_Error)) { if fd == 0 { - return {}, Path_Error{err = .Invalid_Argument}; + return {}, Path_Error{err = .Invalid_Argument} } - context.allocator = allocator; + context.allocator = allocator - path, err := _cleanpath_from_handle(fd); + path, err := _cleanpath_from_handle(fd) if err != nil { - return {}, err; + return {}, err } - h := win32.HANDLE(fd); + h := win32.HANDLE(fd) switch win32.GetFileType(h) { case win32.FILE_TYPE_PIPE, win32.FILE_TYPE_CHAR: - fi: File_Info; - fi.fullpath = path; - fi.name = basename(path); - fi.mode |= file_type_mode(h); - return fi, nil; + fi: File_Info + fi.fullpath = path + fi.name = basename(path) + fi.mode |= file_type_mode(h) + return fi, nil } - return _file_info_from_get_file_information_by_handle(path, h); + return _file_info_from_get_file_information_by_handle(path, h) } _stat :: proc(name: string, allocator := context.allocator) -> (File_Info, Maybe(Path_Error)) { - return internal_stat(name, win32.FILE_FLAG_BACKUP_SEMANTICS); + return internal_stat(name, win32.FILE_FLAG_BACKUP_SEMANTICS) } _lstat :: proc(name: string, allocator := context.allocator) -> (File_Info, Maybe(Path_Error)) { - return internal_stat(name, win32.FILE_FLAG_BACKUP_SEMANTICS|win32.FILE_FLAG_OPEN_REPARSE_POINT); + return internal_stat(name, win32.FILE_FLAG_BACKUP_SEMANTICS|win32.FILE_FLAG_OPEN_REPARSE_POINT) } _same_file :: proc(fi1, fi2: File_Info) -> bool { - return fi1.fullpath == fi2.fullpath; + return fi1.fullpath == fi2.fullpath } _stat_errno :: proc(errno: win32.DWORD) -> Path_Error { - return Path_Error{err = Platform_Error{i32(errno)}}; + return Path_Error{err = Platform_Error{i32(errno)}} } full_path_from_name :: proc(name: string, allocator := context.allocator) -> (path: string, err: Maybe(Path_Error)) { - name := name; + context.allocator = allocator + + name := name if name == "" { - name = "."; + name = "." } - p := win32.utf8_to_utf16(name, context.temp_allocator); - buf := make([dynamic]u16, 100, allocator); + p := win32.utf8_to_utf16(name, context.temp_allocator) + buf := make([dynamic]u16, 100) for { - n := win32.GetFullPathNameW(raw_data(p), u32(len(buf)), raw_data(buf), nil); + n := win32.GetFullPathNameW(raw_data(p), u32(len(buf)), raw_data(buf), nil) if n == 0 { - delete(buf); - return "", _stat_errno(win32.GetLastError()); + delete(buf) + return "", _stat_errno(win32.GetLastError()) } if n <= u32(len(buf)) { - return win32.utf16_to_utf8(buf[:n]), nil; + return win32.utf16_to_utf8(buf[:n]), nil } - resize(&buf, len(buf)*2); + resize(&buf, len(buf)*2) } - return; + return } internal_stat :: proc(name: string, create_file_attributes: u32, allocator := context.allocator) -> (fi: File_Info, e: Maybe(Path_Error)) { if len(name) == 0 { - return {}, Path_Error{err = .Not_Exist}; + return {}, Path_Error{err = .Not_Exist} } - context.allocator = allocator; + context.allocator = allocator - wname := win32.utf8_to_wstring(_fix_long_path(name), context.temp_allocator); - fa: win32.WIN32_FILE_ATTRIBUTE_DATA; - ok := win32.GetFileAttributesExW(wname, win32.GetFileExInfoStandard, &fa); + wname := win32.utf8_to_wstring(_fix_long_path(name), context.temp_allocator) + fa: win32.WIN32_FILE_ATTRIBUTE_DATA + ok := win32.GetFileAttributesExW(wname, win32.GetFileExInfoStandard, &fa) if ok && fa.dwFileAttributes & win32.FILE_ATTRIBUTE_REPARSE_POINT == 0 { // Not a symlink - return _file_info_from_win32_file_attribute_data(&fa, name); + return _file_info_from_win32_file_attribute_data(&fa, name) } - err := 0 if ok else win32.GetLastError(); + err := 0 if ok else win32.GetLastError() if err == win32.ERROR_SHARING_VIOLATION { - fd: win32.WIN32_FIND_DATAW; - sh := win32.FindFirstFileW(wname, &fd); + fd: win32.WIN32_FIND_DATAW + sh := win32.FindFirstFileW(wname, &fd) if sh == win32.INVALID_HANDLE_VALUE { - e = Path_Error{err = Platform_Error{i32(win32.GetLastError())}}; - return; + e = Path_Error{err = Platform_Error{i32(win32.GetLastError())}} + return } - win32.FindClose(sh); + win32.FindClose(sh) - return _file_info_from_win32_find_data(&fd, name); + return _file_info_from_win32_find_data(&fd, name) } - h := win32.CreateFileW(wname, 0, 0, nil, win32.OPEN_EXISTING, create_file_attributes, nil); + h := win32.CreateFileW(wname, 0, 0, nil, win32.OPEN_EXISTING, create_file_attributes, nil) if h == win32.INVALID_HANDLE_VALUE { - e = Path_Error{err = Platform_Error{i32(win32.GetLastError())}}; - return; + e = Path_Error{err = Platform_Error{i32(win32.GetLastError())}} + return } - defer win32.CloseHandle(h); - return _file_info_from_get_file_information_by_handle(name, h); + defer win32.CloseHandle(h) + return _file_info_from_get_file_information_by_handle(name, h) } _cleanpath_strip_prefix :: proc(buf: []u16) -> []u16 { - buf := buf; - N := 0; + buf := buf + N := 0 for c, i in buf { - if c == 0 { break; } - N = i+1; + if c == 0 { break } + N = i+1 } - buf = buf[:N]; + buf = buf[:N] if len(buf) >= 4 { if buf[0] == '\\' && buf[1] == '\\' && buf[2] == '?' && buf[3] == '\\' { - buf = buf[4:]; + buf = buf[4:] } } - return buf; + return buf } _cleanpath_from_handle :: proc(fd: Handle) -> (string, Maybe(Path_Error)) { if fd == 0 { - return "", Path_Error{err = .Invalid_Argument}; + return "", Path_Error{err = .Invalid_Argument} } - h := win32.HANDLE(fd); + h := win32.HANDLE(fd) - MAX_PATH := win32.DWORD(260) + 1; - buf: []u16; + MAX_PATH := win32.DWORD(260) + 1 + buf: []u16 for { - buf = make([]u16, MAX_PATH, context.temp_allocator); - err := win32.GetFinalPathNameByHandleW(h, raw_data(buf), MAX_PATH, 0); + buf = make([]u16, MAX_PATH, context.temp_allocator) + err := win32.GetFinalPathNameByHandleW(h, raw_data(buf), MAX_PATH, 0) switch err { case win32.ERROR_PATH_NOT_FOUND, win32.ERROR_INVALID_PARAMETER: - return "", _stat_errno(err); + return "", _stat_errno(err) case win32.ERROR_NOT_ENOUGH_MEMORY: - MAX_PATH = MAX_PATH*2 + 1; - continue; + MAX_PATH = MAX_PATH*2 + 1 + continue } - break; + break } - return _cleanpath_from_buf(buf), nil; + return _cleanpath_from_buf(buf), nil } _cleanpath_from_handle_u16 :: proc(fd: Handle) -> ([]u16, Maybe(Path_Error)) { if fd == 0 { - return nil, Path_Error{err = .Invalid_Argument}; + return nil, Path_Error{err = .Invalid_Argument} } - h := win32.HANDLE(fd); + h := win32.HANDLE(fd) - MAX_PATH := win32.DWORD(260) + 1; - buf: []u16; + MAX_PATH := win32.DWORD(260) + 1 + buf: []u16 for { - buf = make([]u16, MAX_PATH, context.temp_allocator); - err := win32.GetFinalPathNameByHandleW(h, raw_data(buf), MAX_PATH, 0); + buf = make([]u16, MAX_PATH, context.temp_allocator) + err := win32.GetFinalPathNameByHandleW(h, raw_data(buf), MAX_PATH, 0) switch err { case win32.ERROR_PATH_NOT_FOUND, win32.ERROR_INVALID_PARAMETER: - return nil, _stat_errno(err); + return nil, _stat_errno(err) case win32.ERROR_NOT_ENOUGH_MEMORY: - MAX_PATH = MAX_PATH*2 + 1; - continue; + MAX_PATH = MAX_PATH*2 + 1 + continue } - break; + break } - return _cleanpath_strip_prefix(buf), nil; + return _cleanpath_strip_prefix(buf), nil } _cleanpath_from_buf :: proc(buf: []u16) -> string { - buf := buf; - buf = _cleanpath_strip_prefix(buf); - return win32.utf16_to_utf8(buf, context.allocator); + buf := buf + buf = _cleanpath_strip_prefix(buf) + return win32.utf16_to_utf8(buf, context.allocator) } basename :: proc(name: string) -> (base: string) { - name := name; + name := name if len(name) > 3 && name[:3] == `\\?` { - name = name[3:]; + name = name[3:] } if len(name) == 2 && name[1] == ':' { - return "."; + return "." } else if len(name) > 2 && name[1] == ':' { - name = name[2:]; + name = name[2:] } - i := len(name)-1; + i := len(name)-1 for ; i > 0 && (name[i] == '/' || name[i] == '\\'); i -= 1 { - name = name[:i]; + name = name[:i] } for i -= 1; i >= 0; i -= 1 { if name[i] == '/' || name[i] == '\\' { - name = name[i+1:]; - break; + name = name[i+1:] + break } } - return name; + return name } file_type_mode :: proc(h: win32.HANDLE) -> File_Mode { switch win32.GetFileType(h) { case win32.FILE_TYPE_PIPE: - return File_Mode_Named_Pipe; + return File_Mode_Named_Pipe case win32.FILE_TYPE_CHAR: - return File_Mode_Device | File_Mode_Char_Device; + return File_Mode_Device | File_Mode_Char_Device } - return 0; + return 0 } _file_mode_from_file_attributes :: proc(FileAttributes: win32.DWORD, h: win32.HANDLE, ReparseTag: win32.DWORD) -> (mode: File_Mode) { if FileAttributes & win32.FILE_ATTRIBUTE_READONLY != 0 { - mode |= 0o444; + mode |= 0o444 } else { - mode |= 0o666; + mode |= 0o666 } - is_sym := false; + is_sym := false if FileAttributes & win32.FILE_ATTRIBUTE_REPARSE_POINT == 0 { - is_sym = false; + is_sym = false } else { - is_sym = ReparseTag == win32.IO_REPARSE_TAG_SYMLINK || ReparseTag == win32.IO_REPARSE_TAG_MOUNT_POINT; + is_sym = ReparseTag == win32.IO_REPARSE_TAG_SYMLINK || ReparseTag == win32.IO_REPARSE_TAG_MOUNT_POINT } if is_sym { - mode |= File_Mode_Sym_Link; + mode |= File_Mode_Sym_Link } else { if FileAttributes & win32.FILE_ATTRIBUTE_DIRECTORY != 0 { - mode |= 0o111 | File_Mode_Dir; + mode |= 0o111 | File_Mode_Dir } if h != nil { - mode |= file_type_mode(h); + mode |= file_type_mode(h) } } - return; + return } _file_info_from_win32_file_attribute_data :: proc(d: ^win32.WIN32_FILE_ATTRIBUTE_DATA, name: string) -> (fi: File_Info, e: Maybe(Path_Error)) { - fi.size = i64(d.nFileSizeHigh)<<32 + i64(d.nFileSizeLow); + fi.size = i64(d.nFileSizeHigh)<<32 + i64(d.nFileSizeLow) - fi.mode |= _file_mode_from_file_attributes(d.dwFileAttributes, nil, 0); - fi.is_dir = fi.mode & File_Mode_Dir != 0; + fi.mode |= _file_mode_from_file_attributes(d.dwFileAttributes, nil, 0) + fi.is_dir = fi.mode & File_Mode_Dir != 0 - fi.creation_time = time.unix(0, win32.FILETIME_as_unix_nanoseconds(d.ftCreationTime)); - fi.modification_time = time.unix(0, win32.FILETIME_as_unix_nanoseconds(d.ftLastWriteTime)); - fi.access_time = time.unix(0, win32.FILETIME_as_unix_nanoseconds(d.ftLastAccessTime)); + fi.creation_time = time.unix(0, win32.FILETIME_as_unix_nanoseconds(d.ftCreationTime)) + fi.modification_time = time.unix(0, win32.FILETIME_as_unix_nanoseconds(d.ftLastWriteTime)) + fi.access_time = time.unix(0, win32.FILETIME_as_unix_nanoseconds(d.ftLastAccessTime)) - fi.fullpath, e = full_path_from_name(name); - fi.name = basename(fi.fullpath); + fi.fullpath, e = full_path_from_name(name) + fi.name = basename(fi.fullpath) - return; + return } _file_info_from_win32_find_data :: proc(d: ^win32.WIN32_FIND_DATAW, name: string) -> (fi: File_Info, e: Maybe(Path_Error)) { - fi.size = i64(d.nFileSizeHigh)<<32 + i64(d.nFileSizeLow); + fi.size = i64(d.nFileSizeHigh)<<32 + i64(d.nFileSizeLow) - fi.mode |= _file_mode_from_file_attributes(d.dwFileAttributes, nil, 0); - fi.is_dir = fi.mode & File_Mode_Dir != 0; + fi.mode |= _file_mode_from_file_attributes(d.dwFileAttributes, nil, 0) + fi.is_dir = fi.mode & File_Mode_Dir != 0 - fi.creation_time = time.unix(0, win32.FILETIME_as_unix_nanoseconds(d.ftCreationTime)); - fi.modification_time = time.unix(0, win32.FILETIME_as_unix_nanoseconds(d.ftLastWriteTime)); - fi.access_time = time.unix(0, win32.FILETIME_as_unix_nanoseconds(d.ftLastAccessTime)); + fi.creation_time = time.unix(0, win32.FILETIME_as_unix_nanoseconds(d.ftCreationTime)) + fi.modification_time = time.unix(0, win32.FILETIME_as_unix_nanoseconds(d.ftLastWriteTime)) + fi.access_time = time.unix(0, win32.FILETIME_as_unix_nanoseconds(d.ftLastAccessTime)) - fi.fullpath, e = full_path_from_name(name); - fi.name = basename(fi.fullpath); + fi.fullpath, e = full_path_from_name(name) + fi.name = basename(fi.fullpath) - return; + return } _file_info_from_get_file_information_by_handle :: proc(path: string, h: win32.HANDLE) -> (File_Info, Maybe(Path_Error)) { - d: win32.BY_HANDLE_FILE_INFORMATION; + d: win32.BY_HANDLE_FILE_INFORMATION if !win32.GetFileInformationByHandle(h, &d) { - return {}, _stat_errno(win32.GetLastError()); + return {}, _stat_errno(win32.GetLastError()) } - ti: win32.FILE_ATTRIBUTE_TAG_INFO; + ti: win32.FILE_ATTRIBUTE_TAG_INFO if !win32.GetFileInformationByHandleEx(h, .FileAttributeTagInfo, &ti, size_of(ti)) { - err := win32.GetLastError(); + err := win32.GetLastError() if err != win32.ERROR_INVALID_PARAMETER { - return {}, _stat_errno(err); + return {}, _stat_errno(err) } // Indicate this is a symlink on FAT file systems - ti.ReparseTag = 0; + ti.ReparseTag = 0 } - fi: File_Info; + fi: File_Info - fi.fullpath = path; - fi.name = basename(path); - fi.size = i64(d.nFileSizeHigh)<<32 + i64(d.nFileSizeLow); + fi.fullpath = path + fi.name = basename(path) + fi.size = i64(d.nFileSizeHigh)<<32 + i64(d.nFileSizeLow) - fi.mode |= _file_mode_from_file_attributes(ti.FileAttributes, h, ti.ReparseTag); - fi.is_dir = fi.mode & File_Mode_Dir != 0; + fi.mode |= _file_mode_from_file_attributes(ti.FileAttributes, h, ti.ReparseTag) + fi.is_dir = fi.mode & File_Mode_Dir != 0 - fi.creation_time = time.unix(0, win32.FILETIME_as_unix_nanoseconds(d.ftCreationTime)); - fi.modification_time = time.unix(0, win32.FILETIME_as_unix_nanoseconds(d.ftLastWriteTime)); - fi.access_time = time.unix(0, win32.FILETIME_as_unix_nanoseconds(d.ftLastAccessTime)); + fi.creation_time = time.unix(0, win32.FILETIME_as_unix_nanoseconds(d.ftCreationTime)) + fi.modification_time = time.unix(0, win32.FILETIME_as_unix_nanoseconds(d.ftLastWriteTime)) + fi.access_time = time.unix(0, win32.FILETIME_as_unix_nanoseconds(d.ftLastAccessTime)) - return fi, nil; + return fi, nil } _is_abs :: proc(path: string) -> bool { if len(path) > 0 && path[0] == '/' { - return true; + return true } if len(path) > 2 { switch path[0] { case 'A'..='Z', 'a'..='z': - return path[1] == ':' && is_path_separator(path[2]); + return path[1] == ':' && is_path_separator(path[2]) } } - return false; + return false } _fix_long_path :: proc(path: string) -> string { if len(path) < 248 { - return path; + return path } if len(path) >= 2 && path[:2] == `\\` { - return path; + return path } if !_is_abs(path) { - return path; + return path } - prefix :: `\\?`; + prefix :: `\\?` - path_buf := make([]byte, len(prefix)+len(path)+len(`\`), context.temp_allocator); - copy(path_buf, prefix); - n := len(path); - r, w := 0, len(prefix); + path_buf := make([]byte, len(prefix)+len(path)+len(`\`), context.temp_allocator) + copy(path_buf, prefix) + n := len(path) + r, w := 0, len(prefix) for r < n { switch { case is_path_separator(path[r]): - r += 1; + r += 1 case path[r] == '.' && (r+1 == n || is_path_separator(path[r+1])): - r += 1; + r += 1 case r+1 < n && path[r] == '.' && path[r+1] == '.' && (r+2 == n || is_path_separator(path[r+2])): - return path; + return path case: - path_buf[w] = '\\'; - w += 1; + path_buf[w] = '\\' + w += 1 for ; r < n && !is_path_separator(path[r]); r += 1 { - path_buf[w] = path[r]; - w += 1; + path_buf[w] = path[r] + w += 1 } } } if w == len(`\\?\c:`) { - path_buf[w] = '\\'; - w += 1; + path_buf[w] = '\\' + w += 1 } - return string(path_buf[:w]); + return string(path_buf[:w]) } diff --git a/core/os/os2/temp_file.odin b/core/os/os2/temp_file.odin index 4969a07d9..8ff0e1656 100644 --- a/core/os/os2/temp_file.odin +++ b/core/os/os2/temp_file.odin @@ -2,13 +2,13 @@ package os2 create_temp :: proc(dir, pattern: string) -> (Handle, Error) { - return _create_temp(dir, pattern); + return _create_temp(dir, pattern) } mkdir_temp :: proc(dir, pattern: string, allocator := context.allocator) -> (string, Error) { - return _mkdir_temp(dir, pattern); + return _mkdir_temp(dir, pattern) } temp_dir :: proc(allocator := context.allocator) -> string { - return _temp_dir(allocator); + return _temp_dir(allocator) } diff --git a/core/os/os2/temp_file_windows.odin b/core/os/os2/temp_file_windows.odin index dd050ab48..43f9f43b4 100644 --- a/core/os/os2/temp_file_windows.odin +++ b/core/os/os2/temp_file_windows.odin @@ -4,26 +4,26 @@ package os2 import win32 "core:sys/windows" _create_temp :: proc(dir, pattern: string) -> (Handle, Error) { - return 0, nil; + return 0, nil } _mkdir_temp :: proc(dir, pattern: string, allocator := context.allocator) -> (string, Error) { - return "", nil; + return "", nil } _temp_dir :: proc(allocator := context.allocator) -> string { - b := make([dynamic]u16, u32(win32.MAX_PATH), context.temp_allocator); + b := make([dynamic]u16, u32(win32.MAX_PATH), context.temp_allocator) for { - n := win32.GetTempPathW(u32(len(b)), raw_data(b)); + n := win32.GetTempPathW(u32(len(b)), raw_data(b)) if n > u32(len(b)) { - resize(&b, int(n)); - continue; + resize(&b, int(n)) + continue } if n == 3 && b[1] == ':' && b[2] == '\\' { } else if n > 0 && b[n-1] == '\\' { - n -= 1; + n -= 1 } - return win32.utf16_to_utf8(b[:n], allocator); + return win32.utf16_to_utf8(b[:n], allocator) } } diff --git a/core/os/os2/user.odin b/core/os/os2/user.odin index b23597387..6dd99c621 100644 --- a/core/os/os2/user.odin +++ b/core/os/os2/user.odin @@ -5,64 +5,64 @@ import "core:strings" user_cache_dir :: proc(allocator := context.allocator) -> (dir: string, is_defined: bool) { switch ODIN_OS { case "windows": - dir = get_env("LocalAppData"); + dir = get_env("LocalAppData") if dir != "" { - dir = strings.clone(dir, allocator); + dir = strings.clone(dir, allocator) } case "darwin": - dir = get_env("HOME"); + dir = get_env("HOME") if dir != "" { - dir = strings.concatenate({dir, "/Library/Caches"}, allocator); + dir = strings.concatenate({dir, "/Library/Caches"}, allocator) } case: // All other UNIX systems - dir = get_env("XDG_CACHE_HOME"); + dir = get_env("XDG_CACHE_HOME") if dir == "" { - dir = get_env("HOME"); + dir = get_env("HOME") if dir == "" { - return; + return } - dir = strings.concatenate({dir, "/.cache"}, allocator); + dir = strings.concatenate({dir, "/.cache"}, allocator) } } - is_defined = dir != ""; - return; + is_defined = dir != "" + return } user_config_dir :: proc(allocator := context.allocator) -> (dir: string, is_defined: bool) { switch ODIN_OS { case "windows": - dir = get_env("AppData"); + dir = get_env("AppData") if dir != "" { - dir = strings.clone(dir, allocator); + dir = strings.clone(dir, allocator) } case "darwin": - dir = get_env("HOME"); + dir = get_env("HOME") if dir != "" { - dir = strings.concatenate({dir, "/Library/Application Support"}, allocator); + dir = strings.concatenate({dir, "/Library/Application Support"}, allocator) } case: // All other UNIX systems - dir = get_env("XDG_CACHE_HOME"); + dir = get_env("XDG_CACHE_HOME") if dir == "" { - dir = get_env("HOME"); + dir = get_env("HOME") if dir == "" { - return; + return } - dir = strings.concatenate({dir, "/.config"}, allocator); + dir = strings.concatenate({dir, "/.config"}, allocator) } } - is_defined = dir != ""; - return; + is_defined = dir != "" + return } user_home_dir :: proc() -> (dir: string, is_defined: bool) { - env := "HOME"; + env := "HOME" switch ODIN_OS { case "windows": - env = "USERPROFILE"; + env = "USERPROFILE" } if v := get_env(env); v != "" { - return v, true; + return v, true } - return "", false; + return "", false }