diff --git a/src/fsck_online.c b/src/fsck_online.c index 6d11cb1..2477db5 100644 --- a/src/fsck_online.c +++ b/src/fsck_online.c @@ -28,10 +28,8 @@ #include #include -#include #include #include -#include #include #include "backend.h" @@ -67,10 +65,6 @@ struct fsck_dir { #define FSCK_DIR_DONE ( 1u << 0 ) // Forward declaration start -#ifdef __linux__ -static ssize_t getdents_ (int, void *, size_t); -#endif - static int next_subdir (struct fsck_ctx *, struct fsck_dir *, struct dirent const **); static int open_subdir (int, char const *, uint64_t *); @@ -79,22 +73,6 @@ static void print_help (void); static void print_version (void); // Forward declaration end -#ifdef __linux__ - -// Some libc (e.g., musl) may declare a getdents() function -// in dirent.h with conflicting types. -#define getdents getdents_ -static ssize_t -getdents_ ( - int dirfd, - void *buf, - size_t bufsize -) { - return syscall(SYS_getdents64, dirfd, buf, bufsize); -} - -#endif /* defined(__linux__) */ - static int next_subdir ( struct fsck_ctx *ctx, @@ -112,7 +90,7 @@ next_subdir ( ctx->dent_buf = xrealloc(ctx->dent_buf, ctx->dent_buf_size); } ssize_t nbytes - = getdents(dir->fd, ctx->dent_buf + start, DIRENT_BUFSIZE); + = xgetdents(dir->fd, ctx->dent_buf + start, DIRENT_BUFSIZE); if (nbytes < 0) { log_printf("getdents(): %s", xstrerror(errno)); return -1; diff --git a/src/xstd.h b/src/xstd.h index c267c75..e2ce7d5 100644 --- a/src/xstd.h +++ b/src/xstd.h @@ -26,6 +26,9 @@ #include #include +#include +#include + #include "defs.h" #ifdef HAVE___BUILTIN_EXPECT @@ -84,6 +87,12 @@ } while (0) #endif +#if defined(__linux__) +# define xgetdents(fd, buf, bufsz) syscall(SYS_getdents64, fd, buf, bufsz) +#elif defined(__FreeBSD__) +# define xgetdents(fd, buf, bufsz) getdents(fd, buf, bufsz) +#endif + /** * Prints a message to standard error, and then aborts. */