summaryrefslogtreecommitdiff
path: root/src/internal/tpax_getdents_impl.h
blob: 2f46d63b5546e32820e074b4a6eb98d083e48fe7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**************************************************************/
/*  tpax: a topological pax implementation                    */
/*  Copyright (C) 2020--2024  SysDeer Technologies, LLC       */
/*  Released under GPLv2 and GPLv3; see COPYING.TPAX.         */
/**************************************************************/

#ifndef TPAX_GETDENTS_IMPL_H
#define TPAX_GETDENTS_IMPL_H

#include <sys/types.h>
#include <dirent.h>

/**************************************************************************/
/*                                                                        */
/* provide a (static inlined) wrapper around a modern getdents interface. */
/*                                                                        */
/* see also the PORTING document in the top-level source directory.       */
/*                                                                        */
/**************************************************************************/



/* first priority given to a user-provided emulation */
#if defined (TPAX_GETDENTS_PORTED)

extern long tpax_getdents(int, struct dirent *, size_t);



/* linux & midipix fallback: use the getdents64() system call. */
#elif defined (__linux__) || defined (__midipix__)

#include <sys/syscall.h>

extern long syscall(long, ...);

static long tpax_getdents(int fd, struct dirent * dirents, size_t count)
{
	return syscall(SYS_getdents64,fd,dirents,count);
}



/* freebsd fallback: use the __sys_getdirentries() system call. */
#elif defined (__FreeBSD__)

extern ssize_t __sys_getdirentries(int, struct dirent *, size_t, off_t *);

static long tpax_getdents(int fd, struct dirent * dirents, size_t count)
{
	return __sys_getdirentries(fd,dirents,count,0);
}



/* not covered and no user-provided emulation */
#else

#error tpax: your target requires the emulation of a modern getdents interface.
#error tpax: see the top-level PORTING document for additional information.

#endif

#endif