mirror of
https://git.sr.ht/~cismonx/bookmarkfs
synced 2025-06-07 11:48:51 +00:00
xstd: add xgetdents()
This commit is contained in:
parent
5a28b069c4
commit
e6809b7e84
2 changed files with 10 additions and 23 deletions
|
@ -28,10 +28,8 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <dirent.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#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;
|
||||
|
|
|
@ -26,6 +26,9 @@
|
|||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <dirent.h>
|
||||
#include <sys/syscall.h>
|
||||
|
||||
#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.
|
||||
*/
|
||||
|
|
Loading…
Add table
Reference in a new issue