From 38ce902686b9b6d4d19bfde134b18f997192ba01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Duval?= Date: Mon, 20 May 2019 21:57:28 +0200 Subject: [PATCH] posix: add posix_fadvise(), only error checks. should help for ports. Change-Id: Id504bdb79cb68db4b615f58848e0e1a86ced8d2b Reviewed-on: https://review.haiku-os.org/c/1467 Reviewed-by: Adrien Destugues --- headers/posix/fcntl.h | 10 ++++++++++ src/system/libroot/posix/fcntl.cpp | 20 ++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/headers/posix/fcntl.h b/headers/posix/fcntl.h index d86ca2be4e..e16dd1634c 100644 --- a/headers/posix/fcntl.h +++ b/headers/posix/fcntl.h @@ -67,6 +67,14 @@ #define AT_REMOVEDIR 0x04 /* unlinkat() */ #define AT_EACCESS 0x08 /* faccessat() */ +/* file advisory information, unused by Haiku */ +#define POSIX_FADV_NORMAL 0 /* no advice */ +#define POSIX_FADV_SEQUENTIAL 1 /* expect sequential access */ +#define POSIX_FADV_RANDOM 2 /* expect access in a random order */ +#define POSIX_FADV_WILLNEED 3 /* expect access in the near future */ +#define POSIX_FADV_DONTNEED 4 /* expect no access in the near future */ +#define POSIX_FADV_NOREUSE 5 /* expect access only once */ + /* advisory file locking */ struct flock { @@ -90,6 +98,8 @@ extern int openat(int fd, const char *path, int openMode, ...); extern int fcntl(int fd, int op, ...); +extern int posix_fadvise(int fd, off_t offset, off_t len, int advice); + #ifdef __cplusplus } #endif diff --git a/src/system/libroot/posix/fcntl.cpp b/src/system/libroot/posix/fcntl.cpp index 1a82dec027..49f2f1ce9e 100644 --- a/src/system/libroot/posix/fcntl.cpp +++ b/src/system/libroot/posix/fcntl.cpp @@ -75,3 +75,23 @@ fcntl(int fd, int op, ...) RETURN_AND_SET_ERRNO(error); } + + +int +posix_fadvise(int fd, off_t offset, off_t len, int advice) +{ + if (len < 0 || offset < 0 || advice < POSIX_FADV_NORMAL + || advice > POSIX_FADV_NOREUSE) { + return EINVAL; + } + + struct stat stat; + if (fstat(fd, &stat) < 0) + return EBADF; + if (S_ISFIFO(stat.st_mode)) + return ESPIPE; + + // Haiku does not use this information. + return 0; +} +