diff --git a/mod.zig b/mod.zig index 4e030c064b57819212c5c01e0dbecebb5ff3d32c..bebf87e9209fd03f182af6dca108f03837c86bf7 100644 --- a/mod.zig +++ b/mod.zig @@ -2056,7 +2056,7 @@ pub const libc = struct { /// char *mkdtemp(char *template); /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/mkdtemp.html - pub extern fn mkdtemp(template: [*:0]u8) [*:0]u8; + pub extern fn mkdtemp(template: [*:0]u8) ?[*:0]u8; /// int mkfifo(const char *path, mode_t mode); /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/mkfifo.html @@ -3481,3 +3481,8 @@ pub fn pthread_cond_broadcast(cond: *pthread_cond_t) !void { if (rc != 0) return errno.fromInt(rc); std.debug.assert(rc == 0); } +pub fn mkdtemp(template: [*:0]u8) ![*:0]u8 { + const rc = libc.mkdtemp(template); + if (rc == null) return errno.fromInt(errno.fromLibC()); + return rc.?; +} diff --git a/test.zig b/test.zig index 061f8cfe5fa76f90cacd9bdfc7d27e4bc9293705..4ce5163aea3b26947e7e8f85b743945b26bd73e7 100644 --- a/test.zig +++ b/test.zig @@ -58,4 +58,5 @@ test { _ = &linux.pthread_cond_timedwait; _ = &linux.pthread_cond_signal; _ = &linux.pthread_cond_broadcast; + _ = &linux.mkdtemp; }