authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2025-04-20 16:42:42 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2025-04-20 16:42:42 -07:00
log4c2443935160b023dc181890a2a057b06942c67b
treef25f23b7686e1945480bff87a8148e5181753218
parent425d3fafed49cdf21fe2a18b2e29bea523017ccc

add getpid


2 files changed, 9 insertions(+), 1 deletions(-)

mod.zig+8-1
...@@ -8,6 +8,7 @@ const syscall3 = sys.syscall3;...@@ -8,6 +8,7 @@ const syscall3 = sys.syscall3;
8const syscall4 = sys.syscall4;8const syscall4 = sys.syscall4;
9const syscall5 = sys.syscall5;9const syscall5 = sys.syscall5;
10const syscall6 = sys.syscall6;10const syscall6 = sys.syscall6;
11const pid_t = sys.pid_t;
1112
12fn _errno(rc: usize) enum(c_ushort) { ok, _ } {13fn _errno(rc: usize) enum(c_ushort) { ok, _ } {
13 const signed: isize = @bitCast(rc);14 const signed: isize = @bitCast(rc);
...@@ -237,7 +238,13 @@ pub const setitimer = @compileError("TODO: setitimer");...@@ -237,7 +238,13 @@ pub const setitimer = @compileError("TODO: setitimer");
237// getpid238// getpid
238// pid_t getpid(void);239// pid_t getpid(void);
239// asmlinkage long sys_getpid(void);240// asmlinkage long sys_getpid(void);
240pub const getpid = @compileError("TODO: getpid");241pub fn getpid() errno.Error!pid_t {
242 const r = syscall0(.getpid);
243 return switch (_errno(r)) {
244 .ok => @intCast(r),
245 _ => |c| errno.errorFromInt(@intFromEnum(c)),
246 };
247}
241248
242// sendfile249// sendfile
243// ssize_t sendfile(int out_fd, int in_fd, off_t *_Nullable offset, size_t count);250// ssize_t sendfile(int out_fd, int in_fd, off_t *_Nullable offset, size_t count);
test.zig+1
...@@ -9,4 +9,5 @@ test {...@@ -9,4 +9,5 @@ test {
9 _ = &linux.write;9 _ = &linux.write;
10 _ = &linux.sched_yield;10 _ = &linux.sched_yield;
11 _ = &linux.pause;11 _ = &linux.pause;
12 _ = &linux.getpid;
12}13}