mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-03 22:28:46 +00:00
remove spawn from os, comment sys/posix/spawn
This commit is contained in:
@@ -7,10 +7,8 @@ foreign import pthread "system:System"
|
|||||||
import "base:runtime"
|
import "base:runtime"
|
||||||
import "core:strings"
|
import "core:strings"
|
||||||
import "core:c"
|
import "core:c"
|
||||||
import "core:sys/posix"
|
|
||||||
|
|
||||||
Handle :: distinct i32
|
Handle :: distinct i32
|
||||||
Pid :: distinct i32
|
|
||||||
File_Time :: distinct u64
|
File_Time :: distinct u64
|
||||||
|
|
||||||
INVALID_HANDLE :: ~Handle(0)
|
INVALID_HANDLE :: ~Handle(0)
|
||||||
@@ -679,39 +677,6 @@ get_last_error_string :: proc() -> string {
|
|||||||
return string(_darwin_string_error(__error()^))
|
return string(_darwin_string_error(__error()^))
|
||||||
}
|
}
|
||||||
|
|
||||||
_spawn :: #force_inline proc(path: string, args: []string, envs: []string, file_actions: rawptr, attributes: rawptr, is_spawnp: bool) -> (posix.pid_t, Error) {
|
|
||||||
runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD()
|
|
||||||
path_cstr := strings.clone_to_cstring(path, context.temp_allocator)
|
|
||||||
|
|
||||||
args_cstrs := make([]cstring, len(args) + 2, context.temp_allocator)
|
|
||||||
args_cstrs[0] = strings.clone_to_cstring(path, context.temp_allocator)
|
|
||||||
for i := 0; i < len(args); i += 1 {
|
|
||||||
args_cstrs[i+1] = strings.clone_to_cstring(args[i], context.temp_allocator)
|
|
||||||
}
|
|
||||||
|
|
||||||
envs_cstrs := make([]cstring, len(envs) + 1, context.temp_allocator)
|
|
||||||
for i := 0; i < len(envs); i += 1 {
|
|
||||||
envs_cstrs[i] = strings.clone_to_cstring(envs[i], context.temp_allocator)
|
|
||||||
}
|
|
||||||
|
|
||||||
child_pid: posix.pid_t
|
|
||||||
status: posix.Errno
|
|
||||||
if is_spawnp {
|
|
||||||
status = posix.posix_spawnp(&child_pid, path_cstr, file_actions, attributes, raw_data(args_cstrs), raw_data(envs_cstrs))
|
|
||||||
} else {
|
|
||||||
status = posix.posix_spawn(&child_pid, path_cstr, file_actions, attributes, raw_data(args_cstrs), raw_data(envs_cstrs))
|
|
||||||
}
|
|
||||||
if status != .NONE {
|
|
||||||
return 0, Platform_Error(status)
|
|
||||||
}
|
|
||||||
return child_pid, nil
|
|
||||||
}
|
|
||||||
spawn :: proc(path: string, args: []string, envs: []string, file_actions: rawptr, attributes: rawptr) -> (posix.pid_t, Error) {
|
|
||||||
return _spawn(path, args, envs, file_actions, attributes, false)
|
|
||||||
}
|
|
||||||
spawnp :: proc(path: string, args: []string, envs: []string, file_actions: rawptr, attributes: rawptr) -> (posix.pid_t, Error) {
|
|
||||||
return _spawn(path, args, envs, file_actions, attributes, true)
|
|
||||||
}
|
|
||||||
|
|
||||||
@(require_results)
|
@(require_results)
|
||||||
open :: proc(path: string, flags: int = O_RDONLY, mode: int = 0) -> (handle: Handle, err: Error) {
|
open :: proc(path: string, flags: int = O_RDONLY, mode: int = 0) -> (handle: Handle, err: Error) {
|
||||||
|
|||||||
@@ -7,6 +7,14 @@ when ODIN_OS == .Darwin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
foreign lib {
|
foreign lib {
|
||||||
|
/*
|
||||||
|
Creates a child process from a provided filepath
|
||||||
|
spawnp searches directories on the path for the file
|
||||||
|
|
||||||
|
Returns: 0 on success, with the child pid returned in the pid argument, or error values on failure.
|
||||||
|
|
||||||
|
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/posix_spawn.html ]]
|
||||||
|
*/
|
||||||
posix_spawn :: proc(pid: ^pid_t, path: cstring, file_actions: rawptr, attrp: rawptr, argv: [^]cstring, envp: [^]cstring) -> Errno ---
|
posix_spawn :: proc(pid: ^pid_t, path: cstring, file_actions: rawptr, attrp: rawptr, argv: [^]cstring, envp: [^]cstring) -> Errno ---
|
||||||
posix_spawnp :: proc(pid: ^pid_t, file: cstring, file_actions: rawptr, attrp: rawptr, argv: [^]cstring, envp: [^]cstring) -> Errno ---
|
posix_spawnp :: proc(pid: ^pid_t, file: cstring, file_actions: rawptr, attrp: rawptr, argv: [^]cstring, envp: [^]cstring) -> Errno ---
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user