aboutsummaryrefslogtreecommitdiff
path: root/compat/compat.c
diff options
context:
space:
mode:
Diffstat (limited to 'compat/compat.c')
-rw-r--r--compat/compat.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/compat/compat.c b/compat/compat.c
new file mode 100644
index 0000000..1112146
--- /dev/null
+++ b/compat/compat.c
@@ -0,0 +1,31 @@
+#include "compat.h"
+
+#ifdef NO_STRDUP
+#include "moslib/safe.h"
+#include <string.h>
+char *strdup(const char *s) {
+ char *s2 = mos_safe_malloc(strlen(s) + 1);
+ strcpy(s2, s);
+ return s2;
+}
+#endif // NO_STRDUP
+
+#ifdef NO_MEMMEM
+void *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)
+ return NULL;
+
+ const unsigned char *p = h;
+ const unsigned char *end = p + h_size - n_size + 1;
+ unsigned char c = *(unsigned char *)n;
+ while ((p = memchr(p, c, end - p))) {
+ if (memcmp(p, n, n_size) == 0)
+ return (void *)p;
+ p++;
+ }
+
+ return NULL;
+}
+#endif // NO_MEMMEM