Re-enable os-wrappers-test.c on Darwin, fix errors

Signed-off-by: Torrekie Gen <me@torrekie.dev>
This commit is contained in:
Torrekie 2024-04-20 18:28:46 +08:00 committed by Liang Qi
parent f430ba5bd5
commit f9c13de55d
4 changed files with 43 additions and 9 deletions

View file

@ -23,7 +23,26 @@
* SOFTWARE.
*/
#ifndef __APPLE__
#define _GNU_SOURCE /* For memrchr */
#else
#include <string.h>
/* No memrchr() on Darwin, borrow one from OpenBSD */
static void *
memrchr(const void *s, int c, size_t n)
{
const unsigned char *cp;
if (n != 0) {
cp = (unsigned char *)s + n;
do {
if (*(--cp) == (unsigned char)c)
return((void *)cp);
} while (--n != 0);
}
return(NULL);
}
#endif
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>