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;
88const syscall4 = sys.syscall4;
99const syscall5 = sys.syscall5;
1010const syscall6 = sys.syscall6;
11const pid_t = sys.pid_t;
1112
1213fn _errno(rc: usize) enum(c_ushort) { ok, _ } {
1314 const signed: isize = @bitCast(rc);
......@@ -237,7 +238,13 @@ pub const setitimer = @compileError("TODO: setitimer");
237238// getpid
238239// pid_t getpid(void);
239240// 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
242249// sendfile
243250// ssize_t sendfile(int out_fd, int in_fd, off_t *_Nullable offset, size_t count);
test.zig+1
......@@ -9,4 +9,5 @@ test {
99 _ = &linux.write;
1010 _ = &linux.sched_yield;
1111 _ = &linux.pause;
12 _ = &linux.getpid;
1213}