aboutsummaryrefslogtreecommitdiff
path: root/core/os/os2/pipe_linux.odin
diff options
context:
space:
mode:
authorgingerBill <gingerBill@users.noreply.github.com>2024-10-01 11:30:28 +0100
committerGitHub <noreply@github.com>2024-10-01 11:30:28 +0100
commitaf9ae4897ad9e526d74489ddd12cfae179639ff3 (patch)
tree72135c26ee5a9fe2a4f69dc54184602221b58afc /core/os/os2/pipe_linux.odin
parent9f813a6263629cdae3b33cd027314f9f4a0fefb5 (diff)
parentca9cfc71678d93abc3f9d1aa17ffdb05fbe01f15 (diff)
Merge pull request #4290 from flysand7/pipe-has-datadev-2024-10
[os2/process]: Implement `process_exec`, and `pipe_has_data`
Diffstat (limited to 'core/os/os2/pipe_linux.odin')
-rw-r--r--core/os/os2/pipe_linux.odin26
1 files changed, 26 insertions, 0 deletions
diff --git a/core/os/os2/pipe_linux.odin b/core/os/os2/pipe_linux.odin
index ac3382bc3..852674c69 100644
--- a/core/os/os2/pipe_linux.odin
+++ b/core/os/os2/pipe_linux.odin
@@ -15,3 +15,29 @@ _pipe :: proc() -> (r, w: ^File, err: Error) {
return
}
+
+@(require_results)
+_pipe_has_data :: proc(r: ^File) -> (ok: bool, err: Error) {
+ if r == nil || r.impl == nil {
+ return false, nil
+ }
+ fd := linux.Fd((^File_Impl)(r.impl).fd)
+ poll_fds := []linux.Poll_Fd {
+ linux.Poll_Fd {
+ fd = fd,
+ events = {.IN, .HUP},
+ },
+ }
+ n, errno := linux.poll(poll_fds, 0)
+ if n != 1 || errno != nil {
+ return false, _get_platform_error(errno)
+ }
+ pipe_events := poll_fds[0].revents
+ if pipe_events >= {.IN} {
+ return true, nil
+ }
+ if pipe_events >= {.HUP} {
+ return false, .Broken_Pipe
+ }
+ return false, nil
+} \ No newline at end of file