summaryrefslogtreecommitdiffstats
path: root/bftw.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2015-08-30 14:38:01 -0400
committerTavian Barnes <tavianator@tavianator.com>2015-08-30 14:38:01 -0400
commite24ffc3a9ea195016a9543d9cc4bf99049f245ce (patch)
treec0c3eafca7a2938bffec2ff128ee80422eea17f1 /bftw.c
parentda4b02f9d020f1d701e22921702b156d3c810f4c (diff)
downloadbfs-e24ffc3a9ea195016a9543d9cc4bf99049f245ce.tar.xz
Add -type support.
Fixes #2.
Diffstat (limited to 'bftw.c')
-rw-r--r--bftw.c42
1 files changed, 33 insertions, 9 deletions
diff --git a/bftw.c b/bftw.c
index 75a208c..d5aad22 100644
--- a/bftw.c
+++ b/bftw.c
@@ -489,14 +489,26 @@ int bftw(const char *dirpath, bftw_fn *fn, int nopenfd, int flags, void *ptr) {
#if defined(_DIRENT_HAVE_D_TYPE) || defined(DT_DIR)
switch (de->d_type) {
+ case DT_BLK:
+ ftwbuf.typeflag = BFTW_BLK;
+ break;
+ case DT_CHR:
+ ftwbuf.typeflag = BFTW_CHR;
+ break;
case DT_DIR:
- ftwbuf.typeflag = BFTW_D;
+ ftwbuf.typeflag = BFTW_DIR;
break;
- case DT_REG:
- ftwbuf.typeflag = BFTW_R;
+ case DT_FIFO:
+ ftwbuf.typeflag = BFTW_FIFO;
break;
case DT_LNK:
- ftwbuf.typeflag = BFTW_SL;
+ ftwbuf.typeflag = BFTW_LNK;
+ break;
+ case DT_REG:
+ ftwbuf.typeflag = BFTW_REG;
+ break;
+ case DT_SOCK:
+ ftwbuf.typeflag = BFTW_SOCK;
break;
}
#endif
@@ -508,14 +520,26 @@ int bftw(const char *dirpath, bftw_fn *fn, int nopenfd, int flags, void *ptr) {
ftwbuf.statbuf = &sb;
switch (sb.st_mode & S_IFMT) {
+ case S_IFBLK:
+ ftwbuf.typeflag = BFTW_BLK;
+ break;
+ case S_IFCHR:
+ ftwbuf.typeflag = BFTW_CHR;
+ break;
case S_IFDIR:
- ftwbuf.typeflag = BFTW_D;
+ ftwbuf.typeflag = BFTW_DIR;
break;
- case S_IFREG:
- ftwbuf.typeflag = BFTW_R;
+ case S_IFIFO:
+ ftwbuf.typeflag = BFTW_FIFO;
break;
case S_IFLNK:
- ftwbuf.typeflag = BFTW_SL;
+ ftwbuf.typeflag = BFTW_LNK;
+ break;
+ case S_IFREG:
+ ftwbuf.typeflag = BFTW_REG;
+ break;
+ case S_IFSOCK:
+ ftwbuf.typeflag = BFTW_SOCK;
break;
}
}
@@ -525,7 +549,7 @@ int bftw(const char *dirpath, bftw_fn *fn, int nopenfd, int flags, void *ptr) {
switch (action) {
case BFTW_CONTINUE:
- if (ftwbuf.typeflag == BFTW_D) {
+ if (ftwbuf.typeflag == BFTW_DIR) {
dircache_entry *next = dircache_add(&cache, current, de->d_name);
if (!next) {
goto fail;