how can I parameterize select function in scandir
The scandir() function scans the directory dir, calling select() on each
directory entry as "int(*filter)(const struct dirent *)" How can I pass
pattern value as parameter to fnmatch(const char *pattern, const char
*string, int flags) function used in filter ?
Here my sample code
int my_selectgrf(const struct dirent *namelist)
{
int r = 0;
char my_pattern[] = "*.grf";
r = fnmatch(my_pattern, namelist->d_name, FNM_PERIOD);
return (r==0)?1:0;
}
scandir("/pub/data/grf", &namelist, my_selectgrf, alphasort);
my goal is to be able to use my_pattern as input parameter.
No comments:
Post a Comment