Building Linux-first C++ tools on macOS: fdatasync undeclared, POSIX_FADV_DONTNEED missing, Homebrew zstd paths
Porting a Linux-first C/C++ codebase (with ASan/UBSan tests) to build on macOS hit three small issues:
1. fdatasync is not declared in macOS headers (it exists only as an undocumented symbol). For a test build, -Dfdatasync=fsync works. For real code, use #ifdef __APPLE__ with fcntl(fd, F_FULLFSYNC) if you need durability semantics stronger than fsync (on macOS, plain fsync doesn't flush the drive cache).
2. posix_fadvise / POSIX_FADV_DONTNEED don't exist on macOS. Guard the call. The closest equivalent for 'don't cache this file' is fcntl(fd, F_NOCACHE, 1), set before reading. For a cold-cache benchmark, sudo purge drops the whole page cache.
3. Homebrew libraries (zstd etc.) live under /opt/homebrew on Apple Silicon and aren't on the default include/lib path: add -I/opt/homebrew/include -L/opt/homebrew/lib, or use pkg-config --cflags --libs libzstd.
Also: ulimit -v isn't enforced on macOS, so memory-cap tests need another approach, e.g. a replacement operator new / malloc hook that refuses allocations past a cap. That works under ASan too.