aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMosder <git@mosder.eu>2026-10-06 17:25:17 +0200
committerMosder <git@mosder.eu>2026-10-06 17:25:17 +0200
commit4513d3c2733e63659320a0b4e23af9bdb72440b6 (patch)
treeb8e94e95f303ef8b090621d50f4c05fc76b51ef9
parent7a1f842b91af4f916501eaea991b897e3db4c502 (diff)
added a temporary fix for glibc
-rw-r--r--Makefile3
-rw-r--r--compat/compat.h6
-rw-r--r--include/moslib/safe.h1
-rw-r--r--src/safe.c4
-rw-r--r--src/tester.c14
-rw-r--r--tests/safe_tests.c7
6 files changed, 27 insertions, 8 deletions
diff --git a/Makefile b/Makefile
index d47cade..246d3f9 100644
--- a/Makefile
+++ b/Makefile
@@ -29,7 +29,8 @@ endef
PROBED:= \
$(call probe_fun,string.h,memmem) \
- $(call probe_fun,string.h,strdup)
+ $(call probe_fun,string.h,strdup) \
+ $(call probe_fun,stdlib.h,mkstemp)
CFLAGS+=$(PROBED)
TESTS_CFLAGS+=$(PROBED)
diff --git a/compat/compat.h b/compat/compat.h
index 5f9424d..8a7ef4a 100644
--- a/compat/compat.h
+++ b/compat/compat.h
@@ -22,4 +22,10 @@ extern char *mos_strdup(const char *s);
extern void *mos_memmem(const void *h, size_t h_size, const void *n, size_t n_size);
#endif // NO_MEMMEM
+#ifndef NO_MKSTEMP
+#define mos_mkstemp mkstemp
+#else
+#error mkstemp fallback not implemented
+#endif // NO_MEMMEM
+
#endif // MOSLIB_COMPAT_H
diff --git a/include/moslib/safe.h b/include/moslib/safe.h
index 5f91a9e..1fe9c56 100644
--- a/include/moslib/safe.h
+++ b/include/moslib/safe.h
@@ -5,6 +5,7 @@
#include <stddef.h>
#include <stdio.h>
#include <unistd.h>
+#include <sys/types.h>
#ifndef MOSLIB_SAFE_H
#define MOSLIB_SAFE_H
diff --git a/src/safe.c b/src/safe.c
index 0701939..de49a58 100644
--- a/src/safe.c
+++ b/src/safe.c
@@ -1,3 +1,5 @@
+#include "compat.h"
+
#define MOS_FORCE_PREFIXES
#include "moslib/safe.h"
@@ -90,7 +92,7 @@ int mos_safe_pipe_fn(int fd[2], MosSafeErrInfo info) {
}
int mos_safe_mkstemp_fn(char *path, MosSafeErrInfo info) {
- int fd = mkstemp(path);
+ int fd = mos_mkstemp(path);
if (fd != -1)
return fd;
ERR_MESS("failed to make temporary file");
diff --git a/src/tester.c b/src/tester.c
index 2ab0c87..70e0d24 100644
--- a/src/tester.c
+++ b/src/tester.c
@@ -2,9 +2,11 @@
#include "moslib/tester.h"
#include <stddef.h>
+#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <sys/wait.h>
#include <unistd.h>
#include "moslib/safe.h"
@@ -145,8 +147,10 @@ void mos_test_assert_out_fn(
size_t n = strlen(output);
char *out = mos_safe_calloc(n + 2, 1);
- int tmp = mos_safe_mkstemp(".tmp");
- unlink(".tmp");
+ char f[128];
+ strcpy(f, ".tmpXXXXXX");
+ int tmp = mos_safe_mkstemp(f);
+ unlink(f);
int og = mos_safe_dup(fd);
fflush(NULL);
@@ -182,8 +186,10 @@ void mos_suppress_output_fn(int fd) {
suppressed.ogs[suppressed.n_outs++] = mos_safe_dup(fd);
if (dev_null == -1) {
- dev_null = mos_safe_mkstemp(".dev_null");
- unlink(".dev_null");
+ char f[128];
+ strcpy(f, ".dev_nullXXXXXX");
+ dev_null = mos_safe_mkstemp(f);
+ unlink(f);
}
fflush(NULL);
diff --git a/tests/safe_tests.c b/tests/safe_tests.c
index 2a41700..25cd5f6 100644
--- a/tests/safe_tests.c
+++ b/tests/safe_tests.c
@@ -3,6 +3,7 @@
#include <limits.h>
#include <stdlib.h>
+#include <string.h>
#include <unistd.h>
TEST_HELPER(malloc_exit) {
@@ -117,9 +118,11 @@ TEST(test_safe_pipe) {
}
TEST(test_safe_mkstemp) {
- int fd = safe_mkstemp(".tmp");
+ char f[128];
+ strcpy(f, ".tmpXXXXXX");
+ int fd = safe_mkstemp(f);
test_assert(fd != -1, "Failed to create a temporary file");
- unlink(".tmp");
+ unlink(f);
close(fd);
}