[lonetix/sys] Only use posix_fadvise() and fdatasync() on Linux.

Some platforms don't offer these functions (e.g. Apple).
pull/2/head
Lorenzo Cogotti 3 years ago
parent 207924beac
commit f214c5e42d

@ -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,6 +83,9 @@ Fildes Sys_Fopen(const char *path, FopenMode mode, unsigned flags)
if (flags & FH_NOREUSE)
posix_fadvise(fd, 0, 0, POSIX_FADV_NOREUSE);
}
#endif
USED(flags);
return fd;
}
@ -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()");
}

Loading…
Cancel
Save