mirror of
https://github.com/odin-lang/Odin.git
synced 2026-01-05 04:27:51 +00:00
Begin mocking out the linux stuff on os2
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
95
core/os/os2/process_linux.odin
Normal file
95
core/os/os2/process_linux.odin
Normal file
@@ -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
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
//+build windows
|
||||
//+private file
|
||||
package os2
|
||||
|
||||
|
||||
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user