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; +} +