fixed macos build too
This commit is contained in:
@@ -9,9 +9,6 @@ CFLAGS ?= -O2 -s -std=c11 -Wall -Wextra -march=native
|
|||||||
CPPFLAGS += -D_POSIX_C_SOURCE=200809L -D_DEFAULT_SOURCE
|
CPPFLAGS += -D_POSIX_C_SOURCE=200809L -D_DEFAULT_SOURCE
|
||||||
LDFLAGS ?=
|
LDFLAGS ?=
|
||||||
LDLIBS += -lpthread
|
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 ?=
|
MARCH ?=
|
||||||
|
|
||||||
BINARY := gg
|
BINARY := gg
|
||||||
|
|||||||
@@ -6,6 +6,9 @@
|
|||||||
* Created by Luxferre in 2026, released into the public domain
|
* 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
|
#ifndef _POSIX_C_SOURCE
|
||||||
#define _POSIX_C_SOURCE 200809L
|
#define _POSIX_C_SOURCE 200809L
|
||||||
#endif
|
#endif
|
||||||
@@ -29,7 +32,7 @@
|
|||||||
|
|
||||||
/* sysctlbyname() is the portable way to query CPU count on every BSD family
|
/* sysctlbyname() is the portable way to query CPU count on every BSD family
|
||||||
* (FreeBSD, OpenBSD, NetBSD, DragonFly) and on macOS/Darwin. */
|
* (FreeBSD, OpenBSD, NetBSD, DragonFly) and on macOS/Darwin. */
|
||||||
#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || defined(__APPLE__)
|
#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || defined(__APPLE__)
|
||||||
#include <sys/sysctl.h>
|
#include <sys/sysctl.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -52,7 +55,7 @@
|
|||||||
* all provide it, but only expose the prototype outside strict conformance
|
* all provide it, but only expose the prototype outside strict conformance
|
||||||
* mode, so declare it ourselves when the system has not already. Any libc that
|
* mode, so declare it ourselves when the system has not already. Any libc that
|
||||||
* genuinely lacks it (rare) gets a small portable fallback. */
|
* genuinely lacks it (rare) gets a small portable fallback. */
|
||||||
#if defined(__GLIBC__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || defined(__APPLE__)
|
#if defined(__GLIBC__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || defined(__APPLE__)
|
||||||
#ifndef memmem
|
#ifndef memmem
|
||||||
void *memmem(const void *haystack, size_t haystacklen,
|
void *memmem(const void *haystack, size_t haystacklen,
|
||||||
const void *needle, size_t needlelen);
|
const void *needle, size_t needlelen);
|
||||||
@@ -60,13 +63,13 @@ void *memmem(const void *haystack, size_t haystacklen,
|
|||||||
#else
|
#else
|
||||||
static void *gg_memmem(const void *haystack, size_t haystacklen,
|
static void *gg_memmem(const void *haystack, size_t haystacklen,
|
||||||
const void *needle, size_t needlelen) {
|
const void *needle, size_t needlelen) {
|
||||||
if (needlelen == 0) return (void *)haystack;
|
if(needlelen == 0) return (void *)haystack;
|
||||||
if (haystacklen < needlelen) return NULL;
|
if(haystacklen < needlelen) return NULL;
|
||||||
const unsigned char *h = (const unsigned char *)haystack;
|
const unsigned char *h = (const unsigned char *)haystack;
|
||||||
const unsigned char *n = (const unsigned char *)needle;
|
const unsigned char *n = (const unsigned char *)needle;
|
||||||
const unsigned char *end = h + haystacklen - needlelen;
|
const unsigned char *end = h + haystacklen - needlelen;
|
||||||
for (; h <= end; h++)
|
for(; h <= end; h++)
|
||||||
if (memcmp(h, n, needlelen) == 0) return (void *)h;
|
if(memcmp(h, n, needlelen) == 0) return (void *)h;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
#define memmem gg_memmem
|
#define memmem gg_memmem
|
||||||
@@ -76,15 +79,15 @@ static void *gg_memmem(const void *haystack, size_t haystacklen,
|
|||||||
static long gg_nproc(void) {
|
static long gg_nproc(void) {
|
||||||
#if defined(_SC_NPROCESSORS_ONLN)
|
#if defined(_SC_NPROCESSORS_ONLN)
|
||||||
long n = sysconf(_SC_NPROCESSORS_ONLN);
|
long n = sysconf(_SC_NPROCESSORS_ONLN);
|
||||||
if (n > 0) return n;
|
if(n > 0) return n;
|
||||||
#elif defined(_SC_NPROCESSORS_CONF)
|
#elif defined(_SC_NPROCESSORS_CONF)
|
||||||
long n = sysconf(_SC_NPROCESSORS_CONF);
|
long n = sysconf(_SC_NPROCESSORS_CONF);
|
||||||
if (n > 0) return n;
|
if(n > 0) return n;
|
||||||
#endif
|
#endif
|
||||||
#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || defined(__APPLE__)
|
#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || defined(__APPLE__)
|
||||||
int ncpu = 1;
|
int ncpu = 1;
|
||||||
size_t len = sizeof(ncpu);
|
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;
|
return (long)ncpu;
|
||||||
#endif
|
#endif
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
Reference in New Issue
Block a user