From f214c5e42da1874e000e91a969dfb063701103a3 Mon Sep 17 00:00:00 2001 From: Lorenzo Cogotti Date: Sat, 6 Nov 2021 00:12:07 +0100 Subject: [PATCH] [lonetix/sys] Only use posix_fadvise() and fdatasync() on Linux. Some platforms don't offer these functions (e.g. Apple). --- lonetix/sys/fs_unix.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lonetix/sys/fs_unix.c b/lonetix/sys/fs_unix.c index 91479e1..f68ff44 100755 --- a/lonetix/sys/fs_unix.c +++ b/lonetix/sys/fs_unix.c @@ -73,7 +73,8 @@ Fildes Sys_Fopen(const char *path, FopenMode mode, unsigned flags) Sys_SetErrStat(errno, "open()/mkstemp()"); - // Apply hints + // Apply hints (if possible) +#ifdef __linux__ if (fd >= 0) { if (flags & FH_SEQ) posix_fadvise(fd, 0, 0, POSIX_FADV_SEQUENTIAL); @@ -82,7 +83,10 @@ Fildes Sys_Fopen(const char *path, FopenMode mode, unsigned flags) if (flags & FH_NOREUSE) posix_fadvise(fd, 0, 0, POSIX_FADV_NOREUSE); } - return fd; +#endif + USED(flags); + + return fd; } Sint64 Sys_Fread(Fildes fd, void *buf, size_t nbytes) @@ -173,10 +177,18 @@ Judgement Sys_Fsync(Fildes fd, Boolean fullSync) { errno = 0; +#ifdef __linux__ + // Take advantage of fdatasync() if possible if (fullSync) fsync(fd); else fdatasync(fd); +#else + // Play it safe and portable + USED(fullSync); + + fsync(fd); +#endif return Sys_SetErrStat(errno, "fsync()/fdatasync()"); }