diff options
author | Haru <haru@dotalux.com> | 2019-01-03 23:14:39 +0100 |
---|---|---|
committer | Dastgir <dastgirp@gmail.com> | 2019-10-02 12:12:32 +0530 |
commit | 557384a0628c82303db29ff0b81ac77c8fdb5a1d (patch) | |
tree | 8726dce1a315a52c99f97cc21e20b447f76eb358 /src/common/utils.c | |
parent | d95b2fd08db9acf768bc31e5c6cdb23a61876719 (diff) | |
download | hercules-557384a0628c82303db29ff0b81ac77c8fdb5a1d.tar.gz hercules-557384a0628c82303db29ff0b81ac77c8fdb5a1d.tar.bz2 hercules-557384a0628c82303db29ff0b81ac77c8fdb5a1d.tar.xz hercules-557384a0628c82303db29ff0b81ac77c8fdb5a1d.zip |
Extend the findfile() function with a general purpose context argument
Signed-off-by: Haru <haru@dotalux.com>
Diffstat (limited to 'src/common/utils.c')
-rw-r--r-- | src/common/utils.c | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/src/common/utils.c b/src/common/utils.c index d4c838b56..238ebe65d 100644 --- a/src/common/utils.c +++ b/src/common/utils.c @@ -128,7 +128,7 @@ static char *checkpath(char *path, const char *srcpath) return path; } -void findfile(const char *p, const char *pat, void (func)(const char *)) +void findfile(const char *p, const char *pat, void (func)(const char *, void *context), void *context) { WIN32_FIND_DATAA FindFileData; HANDLE hFind; @@ -155,12 +155,11 @@ void findfile(const char *p, const char *pat, void (func)(const char *)) sprintf(tmppath,"%s%c%s",path,PATHSEP,FindFileData.cFileName); if (strstr(FindFileData.cFileName, pattern)) { - func( tmppath ); + func(tmppath, context); } - if( FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) - { - findfile(tmppath, pat, func); + if ((FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0) { + findfile(tmppath, pat, func, context); } }while (FindNextFileA(hFind, &FindFileData) != 0); FindClose(hFind); @@ -190,7 +189,7 @@ static char *checkpath(char *path, const char *srcpath) return path; } -void findfile(const char *p, const char *pat, void (func)(const char *)) +void findfile(const char *p, const char *pat, void (func)(const char *, void *context), void *context) { DIR* dir; ///< pointer to the scanned directory. struct dirent* entry; ///< pointer to one directory entry. @@ -220,7 +219,7 @@ void findfile(const char *p, const char *pat, void (func)(const char *)) // check if the pattern matches. if (strstr(entry->d_name, pattern)) { - func( tmppath ); + func(tmppath, context); } // check if it is a directory. if (stat(tmppath, &dir_stat) == -1) { @@ -230,7 +229,7 @@ void findfile(const char *p, const char *pat, void (func)(const char *)) // is this a directory? if (S_ISDIR(dir_stat.st_mode)) { // decent recursively - findfile(tmppath, pat, func); + findfile(tmppath, pat, func, context); } }//end while |