diff --git a/mod.zig b/mod.zig index 6cf56c950a7bc5b3fd7b494d38c595264d9309db..57ea43c25ec8b0a8691d6331f078ca3261bf8241 100644 --- a/mod.zig +++ b/mod.zig @@ -1503,6 +1503,10 @@ pub const libc = struct { /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/getchar_unlocked.html pub extern fn getchar_unlocked() c_int; + /// char *getcwd(char *buf, size_t size); + /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/getcwd.html + pub extern fn getcwd(buf: [*]u8, size: usize) ?[*:0]u8; + /// gid_t getegid(void); /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/getegid.html pub extern fn getegid() gid_t; @@ -3713,3 +3717,8 @@ pub fn lseek(fd: c_int, offset: off_t, whence: c_int) !void { if (rc == -1) return errno.fromInt(errno.fromLibC()); std.debug.assert(rc >= 0); } +pub fn getcwd(buf: []u8) ![*:0]u8 { + const rc = libc.getcwd(buf.ptr, buf.len); + if (rc == null) return errno.fromInt(errno.fromLibC()); + return rc.?; +} diff --git a/test.zig b/test.zig index e687df0b2f0d2d09ecd2a7afa1e6a006483a5616..aec2685b985375be1a8485262d221340afa09c59 100644 --- a/test.zig +++ b/test.zig @@ -80,4 +80,5 @@ test { _ = &linux.waitpid; _ = &linux.unlinkat; _ = &linux.lseek; + _ = &linux.getcwd; }