move definition of my_memmem() outside of an #ifdef

This commit is contained in:
stefan schippers 2024-10-28 19:15:13 +01:00
parent c342a1c41f
commit 71d5481dc8
1 changed files with 26 additions and 26 deletions

View File

@ -4076,6 +4076,32 @@ cairo_status_t png_writer(void *in_closure, const unsigned char *in_data, unsign
}
#endif
/*
* The memmem() function finds the start of the first occurrence of the
* substring 'needle' of length 'nlen' in the memory area 'haystack' of
* length 'hlen'.
*
* The return value is a pointer to the beginning of the sub-string, or
* NULL if the substring is not found.
*/
void *my_memmem(const void *haystack, size_t hlen, const void *needle, size_t nlen)
{
int needle_first;
const char *p = haystack;
size_t plen = hlen;
if (!nlen) return NULL;
needle_first = *(unsigned char *)needle;
while (plen >= nlen && (p = memchr(p, needle_first, plen - nlen + 1)))
{
if (!memcmp(p, needle, nlen)) return (void *)p;
p++;
plen = hlen - (p - (char *)haystack);
}
return NULL;
}
#if HAS_CAIRO==1
/* what:
* 1: invert colors
@ -4221,32 +4247,6 @@ int edit_image(int what, xRect *r)
return 1;
}
/*
* The memmem() function finds the start of the first occurrence of the
* substring 'needle' of length 'nlen' in the memory area 'haystack' of
* length 'hlen'.
*
* The return value is a pointer to the beginning of the sub-string, or
* NULL if the substring is not found.
*/
void *my_memmem(const void *haystack, size_t hlen, const void *needle, size_t nlen)
{
int needle_first;
const char *p = haystack;
size_t plen = hlen;
if (!nlen) return NULL;
needle_first = *(unsigned char *)needle;
while (plen >= nlen && (p = memchr(p, needle_first, plen - nlen + 1)))
{
if (!memcmp(p, needle, nlen)) return (void *)p;
p++;
plen = hlen - (p - (char *)haystack);
}
return NULL;
}
/* returns a cairo surface.
* `filename` should be a png or jpeg image or anything else that can be converted to png
* or jpeg via a `filter` pipeline. (example: filter="gm convert - png:-")