bore

basic core utilities (PD)
git clone git://bvnf.space/bore.git
Log | Files | Refs | README

find.c (619B)


      1
      2
      3
      4
      5
      6
      7
      8
      9
     10
     11
     12
     13
     14
     15
     16
     17
     18
     19
     20
     21
     22
     23
     24
     25
     26
     27
     28
     29
#include <errno.h>
#include <ftw.h>
#include <stdio.h>
#include <string.h>

int
foreach(const char *name, const struct stat *sb, int tflag, struct FTW *ftwbuf) {
    printf("%s\n", name);
    /* fnmatch
     * detect infinite loops
     */
    return 0;
}

int
main(int argc, char **argv) {
    char *argv0 = argv[0];
    if (argc < 2) {
        fprintf(stderr, "usage: %s path...\n", argv0);
        return 1;
    }
    while (*(++argv)) {
        if (nftw(*argv, foreach, 20, 0) != 0) {
            fprintf(stderr, "%s: %s: %s\n", argv0, *argv, strerror(errno));
            return 1;
        }
    }
    return 0;
}