foreach ident : [
['set_mempolicy', '''#include <sys/syscall.h>'''], # declared at numaif.h provided by libnuma, which we do not use
['get_mempolicy', '''#include <sys/syscall.h>'''], # declared at numaif.h provided by libnuma, which we do not use
- ['getdents64', '''#include <dirent.h>'''], # since glibc-2.30, but check it for musl
+ ['posix_getdents', '''#include <dirent.h>'''], # glibc does not implement it, but musl does
['strerrorname_np', '''#include <string.h>'''], # since glibc-2.32
['mallinfo', '''#include <malloc.h>'''], # deprecated since glibc-2.33, but check it for musl
['mallinfo2', '''#include <malloc.h>'''], # since glibc-2.33
continue; \
else
+/* Musl provides posix_getdents(). But glibc does not, and provides their own implementation as getdents64().
+ * Let's introduce a simple wrapper. */
+#if !HAVE_POSIX_GETDENTS
+static inline ssize_t posix_getdents(int fd, void *buf, size_t nbyte, int flags) {
+ return getdents64(fd, buf, nbyte);
+}
+#endif
+
/* Maximum space one dirent structure might require at most */
#define DIRENT_SIZE_MAX CONST_MAX(sizeof(struct dirent), offsetof(struct dirent, d_name) + NAME_MAX + 1)
/* ======================================================================= */
-#if !HAVE_GETDENTS64
-static inline ssize_t missing_getdents64(int fd, void *buffer, size_t length) {
- return syscall(__NR_getdents64, fd, buffer, length);
-}
-
-# define getdents64 missing_getdents64
-#endif
-
-/* ======================================================================= */
-
#if !HAVE_SCHED_SETATTR
/* since kernel 3.14 (e6cfc0295c7d51b008999a8b13a44fb43f8685ea) */
static inline ssize_t missing_sched_setattr(pid_t pid, struct sched_attr *attr, unsigned int flags) {
#include "fd-util.h"
#include "fileio.h"
#include "fs-util.h"
-#include "missing_syscall.h"
#include "mountpoint-util.h"
#include "recurse-dir.h"
#include "sort-util.h"
bs = MIN(MALLOC_SIZEOF_SAFE(de) - offsetof(DirectoryEntries, buffer), (size_t) SSIZE_MAX);
assert(bs > de->buffer_size);
- n = getdents64(dir_fd, (uint8_t*) de->buffer + de->buffer_size, bs - de->buffer_size);
+ n = posix_getdents(dir_fd, (uint8_t*) de->buffer + de->buffer_size, bs - de->buffer_size, /* flags = */ 0);
if (n < 0)
return -errno;
if (n == 0)
#include "macro.h"
#include "missing_fs.h"
#include "missing_magic.h"
-#include "missing_syscall.h"
#include "mountpoint-util.h"
#include "nulstr-util.h"
#include "parse-util.h"
struct dirent *de;
ssize_t n;
- n = getdents64(fd, buf, m);
+ n = posix_getdents(fd, buf, m, /* flags = */ 0);
if (n < 0)
return -errno;
if (n == 0)