aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorMosder <git@mosder.eu>2026-09-17 12:37:01 +0200
committerMosder <git@mosder.eu>2026-09-17 12:37:11 +0200
commitde163fe7ee64e63d36dd581db16c776831cbead0 (patch)
tree57f9861bd63a5479c8ee1d829a00d3b4ab053bba /include
parent33e2e9d8aff7ee16aa5c071df93d6f9c0a37e53f (diff)
feat: improved compatibility - removed possible duplicate names, exit tests now create a fork instead of relying on being able to overwrite exit function, made tester only output ASCII escape sequences for colour into a tty
Diffstat (limited to 'include')
-rw-r--r--include/moslib/ds/hashmap.h15
-rw-r--r--include/moslib/safe.h7
2 files changed, 16 insertions, 6 deletions
diff --git a/include/moslib/ds/hashmap.h b/include/moslib/ds/hashmap.h
index 09a27e2..c2a88b9 100644
--- a/include/moslib/ds/hashmap.h
+++ b/include/moslib/ds/hashmap.h
@@ -27,7 +27,7 @@
//
// It accepts these optional arguments:
//
-// .key (enum {DEFAULT, STR, SS}) - use predefined hash and equals functions
+// .key (enum {HM_DEFAULT, HM_STR, HM_SS}) - use predefined hash and equals functions
// for C strings or StringSlice
// .hash (uint32_t (*)(const void *key)) - user defined hash function
// .eq (int (*)(const void *key1, cosnt void *key2)) - user defined equals function
@@ -39,10 +39,10 @@
// Examples:
//
// HM_DEF(str_int, char *, int);
-// str_int *hm1 = hm_new(.key = STR);
+// str_int *hm1 = hm_new(.key = HM_STR);
//
// HM_DEF(ss_float, StringSlice, float);
-// ss_float *hm2 = hm_new(.key = SS);
+// ss_float *hm2 = hm_new(.key = HM_SS);
//
// uint32_t hash_int(const void *key) {
// return (uint32_t)(*(int *)key);
@@ -143,6 +143,9 @@
#ifndef MOS_FORCE_PREFIXES
+#define HM_DEFAULT MOS_HM_DEFAULT
+#define HM_STR MOS_HM_STR
+#define HM_SS MOS_HM_SS
#define HM_DEF MOS_HM_DEF
#define hm_new mos_hm_new
#define hm_put mos_hm_put
@@ -159,7 +162,7 @@
#endif // MOS_FORCE_PREFIXES
typedef struct {
- enum { DEFAULT, STR, SS } key;
+ enum { MOS_HM_DEFAULT, MOS_HM_STR, MOS_HM_SS } key;
uint32_t (*hash)(const void *key);
int (*eq)(const void *key1, const void *key2);
} MosHmNewArgs;
@@ -176,8 +179,8 @@ typedef struct {
// Optional arguments:
// .key
// key specification enum
-// STR - C string hash and equals functions
-// SS - StringSlice hash and equals functions
+// HM_STR - C string hash and equals functions
+// HM_SS - StringSlice hash and equals functions
//
// .hash
// user defined hash function
diff --git a/include/moslib/safe.h b/include/moslib/safe.h
index 18ab5b0..c855cea 100644
--- a/include/moslib/safe.h
+++ b/include/moslib/safe.h
@@ -4,6 +4,7 @@
#include <stddef.h>
#include <stdio.h>
+#include <unistd.h>
#ifndef MOSLIB_SAFE_H
#define MOSLIB_SAFE_H
@@ -17,6 +18,8 @@
#define safe_tmpfile mos_safe_tmpfile
#define safe_dup mos_safe_dup
#define safe_dup2 mos_safe_dup2
+#define safe_fork mos_safe_fork
+#define safe_pipe mos_safe_pipe
#endif // MOS_FORCE_PREFIXES
@@ -37,6 +40,8 @@ typedef struct {
#define mos_safe_tmpfile() mos_safe_tmpfile_fn(mos_err_info)
#define mos_safe_dup(fd) mos_safe_dup_fn(fd, mos_err_info)
#define mos_safe_dup2(fd, fd2) mos_safe_dup2_fn(fd, fd2, mos_err_info)
+#define mos_safe_fork() mos_safe_fork_fn(mos_err_info)
+#define mos_safe_pipe(fd) mos_safe_pipe_fn(fd, mos_err_info)
// Function prototypes for macros
extern void *mos_safe_malloc_fn(size_t size, MosSafeErrInfo info);
@@ -46,5 +51,7 @@ extern FILE *mos_safe_fopen_fn(const char *path, const char *mode, MosSafeErrInf
extern FILE *mos_safe_tmpfile_fn(MosSafeErrInfo info);
extern int mos_safe_dup_fn(int fd, MosSafeErrInfo info);
extern int mos_safe_dup2_fn(int fd, int fd2, MosSafeErrInfo info);
+extern pid_t mos_safe_fork_fn(MosSafeErrInfo info);
+extern int mos_safe_pipe_fn(int fd[2], MosSafeErrInfo info);
#endif // MOSLIB_SAFE_H