|
| 1 | +! unix_ftw.F90 |
| 2 | +! |
| 3 | +! Author: Philipp Engel |
| 4 | +! Licence: ISC |
| 5 | +module unix_ftw |
| 6 | + use, intrinsic :: iso_c_binding |
| 7 | + implicit none |
| 8 | + private |
| 9 | + |
| 10 | +#if defined (__linux__) |
| 11 | + |
| 12 | + integer(kind=c_int), parameter, public :: FTW_F = 0 |
| 13 | + integer(kind=c_int), parameter, public :: FTW_D = 1 |
| 14 | + integer(kind=c_int), parameter, public :: FTW_DNR = 2 |
| 15 | + integer(kind=c_int), parameter, public :: FTW_NS = 3 |
| 16 | + integer(kind=c_int), parameter, public :: FTW_SL = 4 |
| 17 | + integer(kind=c_int), parameter, public :: FTW_DP = 5 |
| 18 | + integer(kind=c_int), parameter, public :: FTW_SLN = 6 |
| 19 | + |
| 20 | + integer(kind=c_int), parameter, public :: FTW_PHYS = 1 |
| 21 | + integer(kind=c_int), parameter, public :: FTW_MOUNT = 2 |
| 22 | + integer(kind=c_int), parameter, public :: FTW_CHDIR = 4 |
| 23 | + integer(kind=c_int), parameter, public :: FTW_DEPTH = 8 |
| 24 | + integer(kind=c_int), parameter, public :: FTW_ACTIONRETVAL = 16 |
| 25 | + |
| 26 | +#elif defined (__FreeBSD__) |
| 27 | + |
| 28 | + integer(kind=c_int), parameter, public :: FTW_F = 0 ! File. |
| 29 | + integer(kind=c_int), parameter, public :: FTW_D = 1 ! Directory. |
| 30 | + integer(kind=c_int), parameter, public :: FTW_DNR = 2 ! Directory without read permission. |
| 31 | + integer(kind=c_int), parameter, public :: FTW_DP = 3 ! Directory with subdirectories visited. |
| 32 | + integer(kind=c_int), parameter, public :: FTW_NS = 4 ! Unknown type; stat() failed. |
| 33 | + integer(kind=c_int), parameter, public :: FTW_SL = 5 ! Symbolic link. |
| 34 | + integer(kind=c_int), parameter, public :: FTW_SLN = 6 ! Sym link that names a nonexistent file. |
| 35 | + |
| 36 | + integer(kind=c_int), parameter, public :: FTW_PHYS = int(z'01') ! Physical walk, don't follow sym links. |
| 37 | + integer(kind=c_int), parameter, public :: FTW_MOUNT = int(z'02') ! The walk does not cross a mount point. |
| 38 | + integer(kind=c_int), parameter, public :: FTW_DEPTH = int(z'04') ! Subdirs visited before the dir itself. |
| 39 | + integer(kind=c_int), parameter, public :: FTW_CHDIR = int(z'08') ! Change to a directory before reading it. |
| 40 | + |
| 41 | +#endif |
| 42 | + |
| 43 | + ! struct FTW |
| 44 | + type, bind(c), public :: c_ftw_type |
| 45 | + integer(kind=c_int) :: base = 0 |
| 46 | + integer(kind=c_int) :: level = 0 |
| 47 | + end type c_ftw_type |
| 48 | + |
| 49 | + public :: c_nftw |
| 50 | + |
| 51 | + interface |
| 52 | + ! int nftw(const char *path, int (*fn)(const char *, const struct stat *, int, struct FTW *), int maxfds, int flags) |
| 53 | + function c_nftw(path, fn, maxfds, flags) bind(c, name='ftw') |
| 54 | + import :: c_char, c_funptr, c_int |
| 55 | + implicit none |
| 56 | + character(kind=c_char), intent(in) :: path |
| 57 | + type(c_funptr), intent(in), value :: fn |
| 58 | + integer(kind=c_int), intent(in), value :: maxfds |
| 59 | + integer(kind=c_int), intent(in), value :: flags |
| 60 | + integer(kind=c_int) :: c_nftw |
| 61 | + end function c_nftw |
| 62 | + end interface |
| 63 | +end module unix_ftw |
0 commit comments