From 07e6d999712be764a20365becb145f7cd1e3119c Mon Sep 17 00:00:00 2001 From: Jakob Kaivo Date: Thu, 21 Apr 2022 19:11:02 -0400 Subject: prep common (n)ftw() implementation --- src/ftw/__ftw.c | 12 ++++++++++++ src/ftw/_ftw.h | 8 ++++++++ src/ftw/ftw.c | 3 ++- src/ftw/nftw.c | 2 +- 4 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 src/ftw/__ftw.c create mode 100644 src/ftw/_ftw.h diff --git a/src/ftw/__ftw.c b/src/ftw/__ftw.c new file mode 100644 index 00000000..2acee0cb --- /dev/null +++ b/src/ftw/__ftw.c @@ -0,0 +1,12 @@ +#include "_ftw.h" + +int __ftw(const char *path, int (*fn)(), int fd_limit, int flags) +{ + struct FTW ft; + struct stat st; + int type = 0; + + int ret = (flags == __FTW_OLD) ? fn(path, &st, type) : fn(path, &st, type, &ft); + + return ret; +} diff --git a/src/ftw/_ftw.h b/src/ftw/_ftw.h new file mode 100644 index 00000000..2225061e --- /dev/null +++ b/src/ftw/_ftw.h @@ -0,0 +1,8 @@ +#ifndef ___FTW_H__ +#define ___FTW_H__ + +#define __FTW_OLD (-1) + +int __ftw(const char *path, int (*fn)(), int fd_limit, int flags); + +#endif diff --git a/src/ftw/ftw.c b/src/ftw/ftw.c index 8bac503e..f500615e 100644 --- a/src/ftw/ftw.c +++ b/src/ftw/ftw.c @@ -1,9 +1,10 @@ #include #include +#include "_ftw.h" int ftw(const char * path, int (*fn) (const char *, const struct stat * ptr, int flag), int ndirs) { - return -1; + return __ftw(path, fn, ndirs, __FTW_OLD); } /* diff --git a/src/ftw/nftw.c b/src/ftw/nftw.c index 8966953c..7dd80dd6 100644 --- a/src/ftw/nftw.c +++ b/src/ftw/nftw.c @@ -2,7 +2,7 @@ int nftw(const char * path, int (*fn) (const char *, const struct stat *, int, struct FTW *), int fd_limit, int flags) { - return 0; + return __ftw(path, fn, fd_limit, flags); } /* -- cgit v1.2.1