diff options
Diffstat (limited to 'xs.h')
| -rw-r--r-- | xs.h | 18 |
1 files changed, 18 insertions, 0 deletions
| @@ -90,6 +90,7 @@ d_char *xs_number_new(double f); | |||
| 90 | double xs_number_get(const char *v); | 90 | double xs_number_get(const char *v); |
| 91 | const char *xs_number_str(const char *v); | 91 | const char *xs_number_str(const char *v); |
| 92 | 92 | ||
| 93 | void *xs_memmem(const char *haystack, int h_size, const char *needle, int n_size); | ||
| 93 | 94 | ||
| 94 | #ifdef XS_IMPLEMENTATION | 95 | #ifdef XS_IMPLEMENTATION |
| 95 | 96 | ||
| @@ -907,6 +908,23 @@ const char *xs_number_str(const char *v) | |||
| 907 | } | 908 | } |
| 908 | 909 | ||
| 909 | 910 | ||
| 911 | void *xs_memmem(const char *haystack, int h_size, const char *needle, int n_size) | ||
| 912 | /* clone of memmem */ | ||
| 913 | { | ||
| 914 | char *p, *r = NULL; | ||
| 915 | int offset = 0; | ||
| 916 | |||
| 917 | while (!r && h_size - offset > n_size && (p = strchr(haystack + offset, *needle))) { | ||
| 918 | if (memcmp(p, needle, n_size) == 0) | ||
| 919 | r = p; | ||
| 920 | else | ||
| 921 | offset = p - haystack + 1; | ||
| 922 | } | ||
| 923 | |||
| 924 | return r; | ||
| 925 | } | ||
| 926 | |||
| 927 | |||
| 910 | #endif /* XS_IMPLEMENTATION */ | 928 | #endif /* XS_IMPLEMENTATION */ |
| 911 | 929 | ||
| 912 | #endif /* _XS_H */ | 930 | #endif /* _XS_H */ |