Blame src/internal/tpax_getdents_impl.h

6f24f4
/******************************************************/
6f24f4
/*  tpax: a topological pax implementation            */
6f24f4
/*  Copyright (C) 2020--2021  Z. Gilboa               */
6f24f4
/*  Released under GPLv2 and GPLv3; see COPYING.TPAX. */
6f24f4
/******************************************************/
6f24f4
6f24f4
#ifndef TPAX_GETDENTS_IMPL_H
6f24f4
#define TPAX_GETDENTS_IMPL_H
6f24f4
6f24f4
#include <sys/types.h>
6f24f4
#include <dirent.h>
6f24f4
6f24f4
/**************************************************************************/
6f24f4
/*                                                                        */
6f24f4
/* provide a (static inlined) wrapper around a modern getdents interface. */
6f24f4
/*                                                                        */
6f24f4
/* see also the PORTING document in the top-level source directory.       */
6f24f4
/*                                                                        */
6f24f4
/**************************************************************************/
6f24f4
6f24f4
6f24f4
6f24f4
/* first priority given to a user-provided emulation */
6f24f4
#if defined (TPAX_GETDENTS_PORTED)
6f24f4
6f24f4
extern long tpax_getdents(int, struct dirent *, size_t);
6f24f4
6f24f4
6f24f4
6f24f4
/* linux & midipix fallback: use the getdents64() system call. */
6f24f4
#elif defined (__linux__) || defined (__midipix__)
6f24f4
6f24f4
#include <sys/syscall.h>
6f24f4
6f24f4
extern long syscall(long, ...);
6f24f4
6f24f4
static long tpax_getdents(int fd, struct dirent * dirents, size_t count)
6f24f4
{
6f24f4
	return syscall(SYS_getdents64,fd,dirents,count);
6f24f4
}
6f24f4
6f24f4
6f24f4
6f24f4
/* freebsd fallback: use the __sys_getdirentries() system call. */
6f24f4
#elif defined (__FreeBSD__)
6f24f4
6f24f4
extern ssize_t __sys_getdirentries(int, struct dirent *, size_t, off_t *);
6f24f4
6f24f4
static long tpax_getdents(int fd, struct dirent * dirents, size_t count)
6f24f4
{
6f24f4
	return __sys_getdirentries(fd,dirents,count,0);
6f24f4
}
6f24f4
6f24f4
6f24f4
6f24f4
/* not covered and no user-provided emulation */
6f24f4
#else
6f24f4
6f24f4
#error tpax: your target requires the emulation of a modern getdents interface.
6f24f4
#error tpax: see the top-level PORTING document for additional information.
6f24f4
6f24f4
#endif
6f24f4
6f24f4
#endif