From 4c2443935160b023dc181890a2a057b06942c67b Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Sun, 20 Apr 2025 16:42:42 -0700 Subject: [PATCH] add getpid --- mod.zig | 9 ++++++++- test.zig | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/mod.zig b/mod.zig index 8f0edaf10462073fd032a33f61633ecc5a507eb8..90588bae432312a7d8cdc6b7a47c714c007043b0 100644 --- a/mod.zig +++ b/mod.zig @@ -8,6 +8,7 @@ const syscall3 = sys.syscall3; const syscall4 = sys.syscall4; const syscall5 = sys.syscall5; const syscall6 = sys.syscall6; +const pid_t = sys.pid_t; fn _errno(rc: usize) enum(c_ushort) { ok, _ } { const signed: isize = @bitCast(rc); @@ -237,7 +238,13 @@ pub const setitimer = @compileError("TODO: setitimer"); // getpid // pid_t getpid(void); // asmlinkage long sys_getpid(void); -pub const getpid = @compileError("TODO: getpid"); +pub fn getpid() errno.Error!pid_t { + const r = syscall0(.getpid); + return switch (_errno(r)) { + .ok => @intCast(r), + _ => |c| errno.errorFromInt(@intFromEnum(c)), + }; +} // sendfile // ssize_t sendfile(int out_fd, int in_fd, off_t *_Nullable offset, size_t count); diff --git a/test.zig b/test.zig index 0c56a714a1ce33f5d622e9250da5ee185cc70f54..4ac00678f4935b29ac72f40847dd9b65a81e78fd 100644 --- a/test.zig +++ b/test.zig @@ -9,4 +9,5 @@ test { _ = &linux.write; _ = &linux.sched_yield; _ = &linux.pause; + _ = &linux.getpid; } -- 2.54.0