summaryrefslogtreecommitdiff
path: root/xs.h
diff options
context:
space:
mode:
authordefault <nobody@localhost>2022-12-11 09:46:27 +0100
committerdefault <nobody@localhost>2022-12-11 09:46:27 +0100
commit0337c71cf45e9b646c1cd4cb39426073623267f2 (patch)
tree95c0ee6d991342c8057e0705d55526967282477b /xs.h
parent79270abd09689e9a7532590e3aa1c016b8cb96c9 (diff)
Backport from xs.
Diffstat (limited to 'xs.h')
-rw-r--r--xs.h18
1 files changed, 18 insertions, 0 deletions
diff --git a/xs.h b/xs.h
index 63342db..3758c8d 100644
--- a/xs.h
+++ b/xs.h
@@ -90,6 +90,7 @@ d_char *xs_number_new(double f);
double xs_number_get(const char *v);
const char *xs_number_str(const char *v);
+void *xs_memmem(const char *haystack, int h_size, const char *needle, int n_size);
#ifdef XS_IMPLEMENTATION
@@ -907,6 +908,23 @@ const char *xs_number_str(const char *v)
}
+void *xs_memmem(const char *haystack, int h_size, const char *needle, int n_size)
+/* clone of memmem */
+{
+ char *p, *r = NULL;
+ int offset = 0;
+
+ while (!r && h_size - offset > n_size && (p = strchr(haystack + offset, *needle))) {
+ if (memcmp(p, needle, n_size) == 0)
+ r = p;
+ else
+ offset = p - haystack + 1;
+ }
+
+ return r;
+}
+
+
#endif /* XS_IMPLEMENTATION */
#endif /* _XS_H */