Parcourir la source

LibC: Implement posix_fadvise() (as a harmless no-op)

Andreas Kling il y a 3 ans
Parent
commit
a7f702a021
2 fichiers modifiés avec 18 ajouts et 1 suppressions
  1. 15 0
      Userland/Libraries/LibC/fcntl.cpp
  2. 3 1
      Userland/Libraries/LibC/fcntl.h

+ 15 - 0
Userland/Libraries/LibC/fcntl.cpp

@@ -87,4 +87,19 @@ int openat(int dirfd, char const* path, int options, ...)
     int rc = syscall(SC_open, &params);
     __RETURN_WITH_ERRNO(rc, rc, -1);
 }
+
+// https://pubs.opengroup.org/onlinepubs/9699919799/functions/posix_fadvise.html
+int posix_fadvise(int fd, off_t offset, off_t len, int advice)
+{
+    // Per POSIX:
+    // "The posix_fadvise() function shall have no effect on the semantics of other operations on the specified data,
+    // although it may affect the performance of other operations."
+
+    // For now, we simply ignore posix_fadvise() requests. In the future we may use them to optimize performance.
+    (void)fd;
+    (void)offset;
+    (void)len;
+    (void)advice;
+    return 0;
+}
 }

+ 3 - 1
Userland/Libraries/LibC/fcntl.h

@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
+ * Copyright (c) 2018-2022, Andreas Kling <kling@serenityos.org>
  * Copyright (c) 2021, sin-ack <sin-ack@protonmail.com>
  *
  * SPDX-License-Identifier: BSD-2-Clause
@@ -20,4 +20,6 @@ int create_inode_watcher(unsigned flags);
 int inode_watcher_add_watch(int fd, char const* path, size_t path_length, unsigned event_mask);
 int inode_watcher_remove_watch(int fd, int wd);
 
+int posix_fadvise(int fd, off_t offset, off_t len, int advice);
+
 __END_DECLS