fixed macos build too

This commit is contained in:
Luxferre
2026-08-21 19:26:31 +03:00
parent 81c53d5dc8
commit 82cfb7ac11
2 changed files with 12 additions and 12 deletions
-3
View File
@@ -9,9 +9,6 @@ CFLAGS ?= -O2 -s -std=c11 -Wall -Wextra -march=native
CPPFLAGS += -D_POSIX_C_SOURCE=200809L -D_DEFAULT_SOURCE
LDFLAGS ?=
LDLIBS += -lpthread
# The matcher uses POSIX memmem(), which glibc accelerates with SIMD on
# whatever CPU you run on. -mavx2 is harmless but unnecessary; drop it for
# maximum portability (e.g. make MARCH="").
MARCH ?=
BINARY := gg
+10 -7
View File
@@ -6,6 +6,9 @@
* Created by Luxferre in 2026, released into the public domain
*
*/
#if defined(__APPLE__) && !defined(_DARWIN_C_SOURCE)
#define _DARWIN_C_SOURCE
#endif
#ifndef _POSIX_C_SOURCE
#define _POSIX_C_SOURCE 200809L
#endif
@@ -60,13 +63,13 @@ void *memmem(const void *haystack, size_t haystacklen,
#else
static void *gg_memmem(const void *haystack, size_t haystacklen,
const void *needle, size_t needlelen) {
if (needlelen == 0) return (void *)haystack;
if (haystacklen < needlelen) return NULL;
if(needlelen == 0) return (void *)haystack;
if(haystacklen < needlelen) return NULL;
const unsigned char *h = (const unsigned char *)haystack;
const unsigned char *n = (const unsigned char *)needle;
const unsigned char *end = h + haystacklen - needlelen;
for (; h <= end; h++)
if (memcmp(h, n, needlelen) == 0) return (void *)h;
for(; h <= end; h++)
if(memcmp(h, n, needlelen) == 0) return (void *)h;
return NULL;
}
#define memmem gg_memmem
@@ -76,15 +79,15 @@ static void *gg_memmem(const void *haystack, size_t haystacklen,
static long gg_nproc(void) {
#if defined(_SC_NPROCESSORS_ONLN)
long n = sysconf(_SC_NPROCESSORS_ONLN);
if (n > 0) return n;
if(n > 0) return n;
#elif defined(_SC_NPROCESSORS_CONF)
long n = sysconf(_SC_NPROCESSORS_CONF);
if (n > 0) return n;
if(n > 0) return n;
#endif
#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || defined(__APPLE__)
int ncpu = 1;
size_t len = sizeof(ncpu);
if (sysctlbyname("hw.ncpu", &ncpu, &len, NULL, 0) == 0 && ncpu > 0)
if(sysctlbyname("hw.ncpu", &ncpu, &len, NULL, 0) == 0 && ncpu > 0)
return (long)ncpu;
#endif
return 1;