aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2024-07-23 16:06:14 +0100
committergingerBill <bill@gingerbill.org>2024-07-23 16:06:14 +0100
commit24f9e2bbeb9382f3ed2da48f3675dbeb2cc2bdbd (patch)
treeb8c324767742857ad3732a883b79d44b9057e666
parent61b9a5dbb296c241137313d6f55974711395eed0 (diff)
Begin mocking out the linux stuff on os2
-rw-r--r--core/os/os2/file.odin14
-rw-r--r--core/os/os2/file_linux.odin49
-rw-r--r--core/os/os2/file_windows.odin19
-rw-r--r--core/os/os2/process_linux.odin95
-rw-r--r--core/os/os2/process_windows.odin1
-rw-r--r--core/os/os2/stat_linux.odin16
6 files changed, 126 insertions, 68 deletions
diff --git a/core/os/os2/file.odin b/core/os/os2/file.odin
index d4abf8f13..8692ecf01 100644
--- a/core/os/os2/file.odin
+++ b/core/os/os2/file.odin
@@ -267,14 +267,24 @@ exists :: proc(path: string) -> bool {
@(require_results)
is_file :: proc(path: string) -> bool {
- return _is_file(path)
+ TEMP_ALLOCATOR_GUARD()
+ fi, err := stat(path, temp_allocator())
+ if err != nil {
+ return false
+ }
+ return fi.type == .Regular
}
is_dir :: is_directory
@(require_results)
is_directory :: proc(path: string) -> bool {
- return _is_dir(path)
+ TEMP_ALLOCATOR_GUARD()
+ fi, err := stat(path, temp_allocator())
+ if err != nil {
+ return false
+ }
+ return fi.type == .Directory
}
diff --git a/core/os/os2/file_linux.odin b/core/os/os2/file_linux.odin
index a8b20c6d9..b567f91d4 100644
--- a/core/os/os2/file_linux.odin
+++ b/core/os/os2/file_linux.odin
@@ -219,15 +219,24 @@ _truncate :: proc(f: ^File, size: i64) -> Error {
}
_remove :: proc(name: string) -> Error {
+ is_dir_fd :: proc(fd: linux.Fd) -> bool {
+ s: linux.Stat
+ if linux.fstat(fd, &s) != .NONE {
+ return false
+ }
+ return linux.S_ISDIR(s.mode)
+ }
+
TEMP_ALLOCATOR_GUARD()
name_cstr := temp_cstring(name) or_return
fd, errno := linux.open(name_cstr, {.NOFOLLOW})
#partial switch (errno) {
- case .ELOOP: /* symlink */
+ case .ELOOP:
+ /* symlink */
case .NONE:
defer linux.close(fd)
- if _is_dir_fd(fd) {
+ if is_dir_fd(fd) {
return _get_platform_error(linux.rmdir(name_cstr))
}
case:
@@ -364,42 +373,6 @@ _exists :: proc(name: string) -> bool {
return !res && errno == .NONE
}
-_is_file :: proc(name: string) -> bool {
- TEMP_ALLOCATOR_GUARD()
- name_cstr, _ := temp_cstring(name)
- s: linux.Stat
- if linux.stat(name_cstr, &s) != .NONE {
- return false
- }
- return linux.S_ISREG(s.mode)
-}
-
-_is_file_fd :: proc(fd: linux.Fd) -> bool {
- s: linux.Stat
- if linux.fstat(fd, &s) != .NONE {
- return false
- }
- return linux.S_ISREG(s.mode)
-}
-
-_is_dir :: proc(name: string) -> bool {
- TEMP_ALLOCATOR_GUARD()
- name_cstr, _ := temp_cstring(name)
- s: linux.Stat
- if linux.stat(name_cstr, &s) != .NONE {
- return false
- }
- return linux.S_ISDIR(s.mode)
-}
-
-_is_dir_fd :: proc(fd: linux.Fd) -> bool {
- s: linux.Stat
- if linux.fstat(fd, &s) != .NONE {
- return false
- }
- return linux.S_ISDIR(s.mode)
-}
-
/* Certain files in the Linux file system are not actual
* files (e.g. everything in /proc/). Therefore, the
* read_entire_file procs fail to actually read anything
diff --git a/core/os/os2/file_windows.odin b/core/os/os2/file_windows.odin
index 97061f281..c69ff1b84 100644
--- a/core/os/os2/file_windows.odin
+++ b/core/os/os2/file_windows.odin
@@ -723,25 +723,6 @@ _exists :: proc(path: string) -> bool {
return attribs != win32.INVALID_FILE_ATTRIBUTES
}
-_is_file :: proc(path: string) -> bool {
- wpath := _fix_long_path(path)
- attribs := win32.GetFileAttributesW(wpath)
- if attribs != win32.INVALID_FILE_ATTRIBUTES {
- return attribs & win32.FILE_ATTRIBUTE_DIRECTORY == 0
- }
- return false
-}
-
-_is_dir :: proc(path: string) -> bool {
- wpath := _fix_long_path(path)
- attribs := win32.GetFileAttributesW(wpath)
- if attribs != win32.INVALID_FILE_ATTRIBUTES {
- return attribs & win32.FILE_ATTRIBUTE_DIRECTORY != 0
- }
- return false
-}
-
-
@(private="package")
_file_stream_proc :: proc(stream_data: rawptr, mode: io.Stream_Mode, p: []byte, offset: i64, whence: io.Seek_From) -> (n: i64, err: io.Error) {
f := (^File_Impl)(stream_data)
diff --git a/core/os/os2/process_linux.odin b/core/os/os2/process_linux.odin
new file mode 100644
index 000000000..d832083b6
--- /dev/null
+++ b/core/os/os2/process_linux.odin
@@ -0,0 +1,95 @@
+//+private file
+package os2
+
+import "base:runtime"
+import "core:time"
+import "core:sys/linux"
+
+@(private="package")
+_exit :: proc "contextless" (code: int) -> ! {
+ linux.exit(i32(code))
+}
+
+
+@(private="package")
+_get_uid :: proc() -> int {
+ return -1
+}
+
+@(private="package")
+_get_euid :: proc() -> int {
+ return -1
+}
+
+@(private="package")
+_get_gid :: proc() -> int {
+ return -1
+}
+
+@(private="package")
+_get_egid :: proc() -> int {
+ return -1
+}
+
+@(private="package")
+_get_pid :: proc() -> int {
+ return -1
+}
+
+@(private="package")
+_get_ppid :: proc() -> int {
+ return -1
+}
+
+@(private="package")
+_process_list :: proc(allocator: runtime.Allocator) -> (list: []int, err: Error) {
+ return
+}
+
+@(private="package")
+_process_info_by_pid :: proc(pid: int, selection: Process_Info_Fields, allocator: runtime.Allocator) -> (info: Process_Info, err: Error) {
+ return
+}
+
+@(private="package")
+_process_info_by_handle :: proc(process: Process, selection: Process_Info_Fields, allocator: runtime.Allocator) -> (info: Process_Info, err: Error) {
+ return
+}
+
+@(private="package")
+_current_process_info :: proc(selection: Process_Info_Fields, allocator: runtime.Allocator) -> (info: Process_Info, err: Error) {
+ return
+}
+
+@(private="package")
+_process_open :: proc(pid: int, flags: Process_Open_Flags) -> (process: Process, err: Error) {
+ return
+}
+
+@(private="package")
+_Sys_Process_Attributes :: struct {}
+
+@(private="package")
+_process_start :: proc(desc: Process_Desc) -> (process: Process, err: Error) {
+ return
+}
+
+@(private="package")
+_process_wait :: proc(process: Process, timeout: time.Duration) -> (process_state: Process_State, err: Error) {
+ return
+}
+
+@(private="package")
+_process_close :: proc(process: Process) -> Error {
+ return nil
+}
+
+@(private="package")
+_process_kill :: proc(process: Process) -> Error {
+ return nil
+}
+
+@(private="package")
+_process_exe_by_pid :: proc(pid: int, allocator: runtime.Allocator) -> (exe_path: string, err: Error) {
+ return
+} \ No newline at end of file
diff --git a/core/os/os2/process_windows.odin b/core/os/os2/process_windows.odin
index 8d61e7be7..d441e7aff 100644
--- a/core/os/os2/process_windows.odin
+++ b/core/os/os2/process_windows.odin
@@ -1,4 +1,3 @@
-//+build windows
//+private file
package os2
diff --git a/core/os/os2/stat_linux.odin b/core/os/os2/stat_linux.odin
index f194524a7..c09f9b299 100644
--- a/core/os/os2/stat_linux.odin
+++ b/core/os/os2/stat_linux.odin
@@ -19,15 +19,15 @@ _fstat_internal :: proc(fd: linux.Fd, allocator: runtime.Allocator) -> (File_Inf
}
type := File_Type.Regular
switch s.mode & linux.S_IFMT {
- case linux.S_IFBLK: type = .Block_Device
- case linux.S_IFCHR: type = .Character_Device
- case linux.S_IFDIR: type = .Directory
- case linux.S_IFIFO: type = .Named_Pipe
- case linux.S_IFLNK: type = .Symlink
- case linux.S_IFREG: type = .Regular
- case linux.S_IFSOCK: type = .Socket
+ case linux.S_IFBLK: type = .Block_Device
+ case linux.S_IFCHR: type = .Character_Device
+ case linux.S_IFDIR: type = .Directory
+ case linux.S_IFIFO: type = .Named_Pipe
+ case linux.S_IFLNK: type = .Symlink
+ case linux.S_IFREG: type = .Regular
+ case linux.S_IFSOCK: type = .Socket
}
- mode := int(s.mode) & 0o7777
+ mode := int(0o7777 & transmute(u32)s.mode)
// TODO: As of Linux 4.11, the new statx syscall can retrieve creation_time
fi := File_Info {
fullpath = _get_full_path(fd, allocator),