tests: Provide memrchr() fallback for platforms that lack it

darwin does not provide memrchr(). Add a local fallback implementation
guarded by HAVE_MEMRCHR.

Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
This commit is contained in:
Jeremy Huddleston Sequoia 2026-04-19 10:35:54 -07:00
parent 2454dd0eec
commit 0815bd0a74
2 changed files with 15 additions and 0 deletions

View file

@ -49,6 +49,7 @@ endforeach
have_funcs = [
'accept4',
'getpeereid',
'memrchr',
'mkostemp',
'posix_fallocate',
'ppoll',

View file

@ -24,6 +24,7 @@
*/
#define _GNU_SOURCE /* For memrchr */
#include "../config.h"
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
@ -36,6 +37,19 @@
#include <assert.h>
#include <signal.h>
#ifndef HAVE_MEMRCHR
static void *
memrchr(const void *s, int c, size_t n)
{
const unsigned char *p = (const unsigned char *)s + n;
while (n--) {
if (*--p == (unsigned char)c)
return (void *)p;
}
return NULL;
}
#endif
#include "wayland-client.h"
#include "wayland-server.h"
#include "test-runner.h"