496
496
return CL_SUCCESS;
499
static int cli_ftw_dir(const char *dirname, int flags, int maxdepth, cli_ftw_cb callback, struct cli_ftw_cbdata *data);
500
static int handle_entry(struct dirent_data *entry, int flags, int maxdepth, cli_ftw_cb callback, struct cli_ftw_cbdata *data)
499
static int cli_ftw_dir(const char *dirname, int flags, int maxdepth, cli_ftw_cb callback, struct cli_ftw_cbdata *data, cli_ftw_pathchk pathchk);
500
static int handle_entry(struct dirent_data *entry, int flags, int maxdepth, cli_ftw_cb callback, struct cli_ftw_cbdata *data, cli_ftw_pathchk pathchk)
502
502
if (!entry->is_dir) {
503
503
return callback(entry->statbuf, entry->filename, entry->filename, visit_file, data);
505
return cli_ftw_dir(entry->dirname, flags, maxdepth, callback, data);
505
return cli_ftw_dir(entry->dirname, flags, maxdepth, callback, data, pathchk);
509
int cli_ftw(char *path, int flags, int maxdepth, cli_ftw_cb callback, struct cli_ftw_cbdata *data)
509
int cli_ftw(char *path, int flags, int maxdepth, cli_ftw_cb callback, struct cli_ftw_cbdata *data, cli_ftw_pathchk pathchk)
511
511
struct stat statbuf;
512
512
enum filetype ft = ft_unknown;
513
513
struct dirent_data entry;
518
if ((flags & CLI_FTW_TRIM_SLASHES) && path[0] && path[1]) {
517
if (((flags & CLI_FTW_TRIM_SLASHES) || pathchk) && path[0] && path[1]) {
520
519
/* trim slashes so that dir and dir/ behave the same when
521
520
* they are symlinks, and we are not following symlinks */
524
523
while (pathend > path && pathend[-1] == '/') --pathend;
526
if(pathchk && pathchk(path, data) == 1)
527
528
ret = handle_filetype(path, flags, &statbuf, &stated, &ft, callback, data);
528
529
if (ret != CL_SUCCESS)
538
539
if (ret != CL_SUCCESS)
541
return handle_entry(&entry, flags, maxdepth, callback, data);
542
return handle_entry(&entry, flags, maxdepth, callback, data, pathchk);
544
static int cli_ftw_dir(const char *dirname, int flags, int maxdepth, cli_ftw_cb callback, struct cli_ftw_cbdata *data)
545
static int cli_ftw_dir(const char *dirname, int flags, int maxdepth, cli_ftw_cb callback, struct cli_ftw_cbdata *data, cli_ftw_pathchk pathchk)
547
548
#if defined(HAVE_READDIR_R_3) || defined(HAVE_READDIR_R_2)
618
619
sprintf(fname, "%s/%s", dirname, dent->d_name);
621
if(pathchk && pathchk(fname, data) == 1) {
620
626
ret = handle_filetype(fname, flags, &statbuf, &stated, &ft, callback, data);
621
627
if (ret != CL_SUCCESS) {
674
680
qsort(entries, entries_cnt, sizeof(*entries), ftw_compare);
675
681
for (i = 0; i < entries_cnt; i++) {
676
682
struct dirent_data *entry = &entries[i];
677
ret = handle_entry(entry, flags, maxdepth-1, callback, data);
683
ret = handle_entry(entry, flags, maxdepth-1, callback, data, pathchk);
678
684
if (entry->is_dir)
679
685
free(entry->filename);
680
686
if (entry->statbuf)
739
749
if(name_salt[0] == 16) { /* minimizes re-seeding after the first call to cli_gentemp() */
740
750
struct timeval tv;
741
751
gettimeofday(&tv, (struct timezone *) 0);
742
srand(tv.tv_usec+clock());
752
srand(tv.tv_usec+clock()+rand());
745
755
return 1 + (unsigned int) (max * (rand() / (1.0 + RAND_MAX)));