[lonetix/sys] Only use posix_fadvise() and fdatasync() on Linux.
Some platforms don't offer these functions (e.g. Apple).
This commit is contained in:
parent
207924beac
commit
f214c5e42d
|
@ -73,7 +73,8 @@ Fildes Sys_Fopen(const char *path, FopenMode mode, unsigned flags)
|
||||||
|
|
||||||
Sys_SetErrStat(errno, "open()/mkstemp()");
|
Sys_SetErrStat(errno, "open()/mkstemp()");
|
||||||
|
|
||||||
// Apply hints
|
// Apply hints (if possible)
|
||||||
|
#ifdef __linux__
|
||||||
if (fd >= 0) {
|
if (fd >= 0) {
|
||||||
if (flags & FH_SEQ)
|
if (flags & FH_SEQ)
|
||||||
posix_fadvise(fd, 0, 0, POSIX_FADV_SEQUENTIAL);
|
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)
|
if (flags & FH_NOREUSE)
|
||||||
posix_fadvise(fd, 0, 0, POSIX_FADV_NOREUSE);
|
posix_fadvise(fd, 0, 0, POSIX_FADV_NOREUSE);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
USED(flags);
|
||||||
|
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -173,10 +177,18 @@ Judgement Sys_Fsync(Fildes fd, Boolean fullSync)
|
||||||
{
|
{
|
||||||
errno = 0;
|
errno = 0;
|
||||||
|
|
||||||
|
#ifdef __linux__
|
||||||
|
// Take advantage of fdatasync() if possible
|
||||||
if (fullSync)
|
if (fullSync)
|
||||||
fsync(fd);
|
fsync(fd);
|
||||||
else
|
else
|
||||||
fdatasync(fd);
|
fdatasync(fd);
|
||||||
|
#else
|
||||||
|
// Play it safe and portable
|
||||||
|
USED(fullSync);
|
||||||
|
|
||||||
|
fsync(fd);
|
||||||
|
#endif
|
||||||
|
|
||||||
return Sys_SetErrStat(errno, "fsync()/fdatasync()");
|
return Sys_SetErrStat(errno, "fsync()/fdatasync()");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue