Backport from xs.

This commit is contained in:
default 2022-12-11 09:46:27 +01:00
parent 79270abd09
commit 0337c71cf4
3 changed files with 22 additions and 6 deletions

18
xs.h
View File

@ -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 */

View File

@ -69,8 +69,6 @@ d_char *xs_url_vars(char *str)
}
void *memmem(const void *, size_t, const void *, size_t);
d_char *_xs_multipart_form_data(char *payload, int p_size, char *header)
/* parses a multipart/form-data payload */
{
@ -94,7 +92,7 @@ d_char *_xs_multipart_form_data(char *payload, int p_size, char *header)
d_char *p_vars = xs_dict_new();
/* iterate searching the boundaries */
while ((p = memmem(payload + offset, p_size - offset, boundary, bsz)) != NULL) {
while ((p = xs_memmem(payload + offset, p_size - offset, boundary, bsz)) != NULL) {
xs *s1 = NULL;
xs *l1 = NULL;
char *vn = NULL;
@ -133,13 +131,13 @@ d_char *_xs_multipart_form_data(char *payload, int p_size, char *header)
}
/* find the start of the part content */
if ((p = memmem(p, p_size - offset, "\r\n\r\n", 4)) == NULL)
if ((p = xs_memmem(p, p_size - offset, "\r\n\r\n", 4)) == NULL)
break;
p += 4;
/* find the next boundary */
if ((q = memmem(p, p_size - offset, boundary, bsz)) == NULL)
if ((q = xs_memmem(p, p_size - offset, boundary, bsz)) == NULL)
break;
po = p - payload;

View File

@ -1 +1 @@
/* ad1c7ba748725abdecc1f1124d697f9130c49e87 */
/* 3aa82bc4fc310ec95194602bed88a9767e100350 */