From 77cddfcc59ca5e65ebdca13492ab7b1307550e97 Mon Sep 17 00:00:00 2001 From: Mosder Date: Thu, 17 Sep 2026 16:23:22 +0200 Subject: fix: added missing macro and missing tests for new safe functions --- include/moslib/safe.h | 1 + tests/safe_tests.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/include/moslib/safe.h b/include/moslib/safe.h index 7e9d817..5f91a9e 100644 --- a/include/moslib/safe.h +++ b/include/moslib/safe.h @@ -20,6 +20,7 @@ #define safe_dup2 mos_safe_dup2 #define safe_fork mos_safe_fork #define safe_pipe mos_safe_pipe +#define safe_mkstemp mos_safe_mkstemp #endif // MOS_FORCE_PREFIXES diff --git a/tests/safe_tests.c b/tests/safe_tests.c index 3c25dd5..2a41700 100644 --- a/tests/safe_tests.c +++ b/tests/safe_tests.c @@ -101,6 +101,32 @@ TEST(test_safe_dup2) { unsuppress_outputs(); } +TEST(test_safe_fork) { + pid_t pid = safe_fork(); + test_assert(pid != -1, "Failed to create a child process"); + if (pid == 0) + exit(EXIT_SUCCESS); +} + +TEST(test_safe_pipe) { + int fd[2]; + int res = safe_pipe(fd); + test_assert(res != -1, "Failed to create a pipe"); + close(fd[0]); + close(fd[1]); +} + +TEST(test_safe_mkstemp) { + int fd = safe_mkstemp(".tmp"); + test_assert(fd != -1, "Failed to create a temporary file"); + unlink(".tmp"); + close(fd); +} + +#define mos_safe_fork() mos_safe_fork_fn(mos_err_info) +#define mos_safe_pipe(fd) mos_safe_pipe_fn(fd, mos_err_info) +#define mos_safe_mkstemp(path) mos_safe_mkstemp_fn(path, mos_err_info) + void safe_tests(Tester *tester) { TestGroup *group = add_test_group(tester, "moslib/safe.h"); add_test(group, test_safe_malloc); @@ -110,4 +136,7 @@ void safe_tests(Tester *tester) { add_test(group, test_safe_tmpfile); add_test(group, test_safe_dup); add_test(group, test_safe_dup2); + add_test(group, test_safe_fork); + add_test(group, test_safe_pipe); + add_test(group, test_safe_mkstemp); } -- cgit v1.2.3