aboutsummaryrefslogtreecommitdiff
path: root/compat/compat.h
blob: 0279eda4129db3618d6a2eb602cc6e55e9383737 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// compat.h
// Compatibility layer for functions not in standard C99

#ifndef MOSLIB_COMPAT_H
#define MOSLIB_COMPAT_H

#define _GNU_SOURCE      1 // glibc, musl, Bionic, Cygwin
#define _ALL_SOURCE      1 // AIX, z/OS, musl
#define _DARWIN_C_SOURCE 1 // macOS
#define _NETBSD_SOURCE   1 // NetBSD
#define _OPENBSD_SOURCE  1 // OpenBSD
#define __EXTENSIONS__   1 // Solaris

// In C99 TU needs a declaration (which won't be the case if all functions are available)
typedef void mos_compat_decl;

#ifndef NO_STRDUP
#define mos_strdup strdup
#else
extern char *mos_strdup(const char *s);
#endif // NO_STRDUP

#ifndef NO_MEMMEM
#define mos_memmem memmem
#else
#include <stddef.h>
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