diff options
| author | Mosder <git@mosder.eu> | 2026-09-28 13:27:35 +0200 |
|---|---|---|
| committer | Mosder <git@mosder.eu> | 2026-09-28 13:27:35 +0200 |
| commit | 7a1f842b91af4f916501eaea991b897e3db4c502 (patch) | |
| tree | c2e9c5180a45585ff9e61158a4395ca066050a01 /compat | |
| parent | b79ccf95459e7edb303dabfe3a26e624bd9d8679 (diff) | |
refactor: prefixed compat functions (and added a macro to libc implementations - if they exist), so they do not take reserved names anymore
Diffstat (limited to 'compat')
| -rw-r--r-- | compat/compat.c | 4 | ||||
| -rw-r--r-- | compat/compat.h | 15 |
2 files changed, 12 insertions, 7 deletions
diff --git a/compat/compat.c b/compat/compat.c index 37432bf..4d8526c 100644 --- a/compat/compat.c +++ b/compat/compat.c @@ -3,7 +3,7 @@ #ifdef NO_STRDUP #include <stdlib.h> #include <string.h> -char *strdup(const char *s) { +char *mos_strdup(const char *s) { char *s2 = malloc(strlen(s) + 1); if (!s2) return NULL; @@ -13,7 +13,7 @@ char *strdup(const char *s) { #endif // NO_STRDUP #ifdef NO_MEMMEM -void *memmem(const void *h, size_t h_size, const void *n, size_t n_size) { +void *mos_memmem(const void *h, size_t h_size, const void *n, size_t n_size) { if (n_size == 0) return (void *)h; if (n_size > h_size) diff --git a/compat/compat.h b/compat/compat.h index 3e46993..5f9424d 100644 --- a/compat/compat.h +++ b/compat/compat.h @@ -6,15 +6,20 @@ #define _GNU_SOURCE -typedef void declaration; +// In C99 TU needs a declaration (which won't be the case if all functions are available) +typedef void mos_compat_decl; -#ifdef NO_STRDUP -extern char *strdup(const char *s); +#ifndef NO_STRDUP +#define mos_strdup strdup +#else +extern char *mos_strdup(const char *s); #endif // NO_STRDUP -#ifdef NO_MEMMEM +#ifndef NO_MEMMEM +#define mos_memmem memmem +#else #include <stddef.h> -extern void *memmem(const void *h, size_t h_size, const void *n, size_t n_size); +extern void *mos_memmem(const void *h, size_t h_size, const void *n, size_t n_size); #endif // NO_MEMMEM #endif // MOSLIB_COMPAT_H |
