# #
#############################################################################*/
-#include <errno.h>
-#include <fnmatch.h>
-#include <ftw.h>
-#include <stddef.h>
-#include <stdio.h>
-
#include "util.h"
-
-int nw_ftw(const char* path, const char* filter,
- int (*callback)(const char* path, const struct stat* s, void* data), void* data) {
- /*
- This is a nested function which allows us to pass some custom pointer to
- the callback function as that isn't possible with nftw().
- */
- int __callback(const char* p, const struct stat* s, int type, struct FTW* ftw) {
- int r;
-
- // Filter out anything we don't want
- if (filter) {
- r = fnmatch(filter, p, FNM_PATHNAME);
-
- switch (r) {
- // Pattern didn't match
- case FNM_NOMATCH:
- return 0;
-
- // Pattern matched
- case 0:
- break;
-
- // Error
- default:
- return 1;
- }
- }
-
- return callback(p, s, data);
- }
-
- return nftw(path, __callback, 0, 0);
-}
#ifndef NETWORKD_UTIL_H
#define NETWORKD_UTIL_H
-#include <sys/stat.h>
-
-int nw_ftw(const char* path, const char* filter,
- int (*callback)(const char* path, const struct stat* s, void* data), void* data);
-
#endif /* NETWORKD_UTIL_H */