summaryrefslogtreecommitdiffstats
path: root/bftw.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2017-02-08 19:15:11 -0500
committerTavian Barnes <tavianator@tavianator.com>2017-02-08 19:31:58 -0500
commita4dcfe8b6d1eaabe172322a81721f355647257ff (patch)
tree1b9a91ed1c1bf7e92bbc55d0ce8fce685b4ca090 /bftw.c
parent360bb95f1d0296efd8c784b13b05daf289336684 (diff)
downloadbfs-a4dcfe8b6d1eaabe172322a81721f355647257ff.tar.xz
Add support for -x?type with multiple types
This functionality is already part of GNU findutils git.
Diffstat (limited to 'bftw.c')
-rw-r--r--bftw.c56
1 files changed, 26 insertions, 30 deletions
diff --git a/bftw.c b/bftw.c
index d62a71f..d239d40 100644
--- a/bftw.c
+++ b/bftw.c
@@ -523,67 +523,63 @@ static void ftwbuf_use_dirent(struct BFTW *ftwbuf, const struct dirent *de) {
#endif
}
-/** Call stat() and use the results. */
-static int ftwbuf_stat(struct BFTW *ftwbuf, struct stat *sb) {
- int ret = fstatat(ftwbuf->at_fd, ftwbuf->at_path, sb, ftwbuf->at_flags);
- if (ret != 0) {
- return ret;
- }
-
- ftwbuf->statbuf = sb;
-
- switch (sb->st_mode & S_IFMT) {
+enum bftw_typeflag bftw_mode_to_typeflag(mode_t mode) {
+ switch (mode & S_IFMT) {
#ifdef S_IFBLK
case S_IFBLK:
- ftwbuf->typeflag = BFTW_BLK;
- break;
+ return BFTW_BLK;
#endif
#ifdef S_IFCHR
case S_IFCHR:
- ftwbuf->typeflag = BFTW_CHR;
- break;
+ return BFTW_CHR;
#endif
#ifdef S_IFDIR
case S_IFDIR:
- ftwbuf->typeflag = BFTW_DIR;
- break;
+ return BFTW_DIR;
#endif
#ifdef S_IFDOOR
case S_IFDOOR:
- ftwbuf->typeflag = BFTW_DOOR;
- break;
+ return BFTW_DOOR;
#endif
#ifdef S_IFIFO
case S_IFIFO:
- ftwbuf->typeflag = BFTW_FIFO;
- break;
+ return BFTW_FIFO;
#endif
#ifdef S_IFLNK
case S_IFLNK:
- ftwbuf->typeflag = BFTW_LNK;
- break;
+ return BFTW_LNK;
#endif
#ifdef S_IFPORT
case S_IFPORT:
- ftwbuf->typeflag = BFTW_PORT;
- break;
+ return BFTW_PORT;
#endif
#ifdef S_IFREG
case S_IFREG:
- ftwbuf->typeflag = BFTW_REG;
- break;
+ return BFTW_REG;
#endif
#ifdef S_IFSOCK
case S_IFSOCK:
- ftwbuf->typeflag = BFTW_SOCK;
- break;
+ return BFTW_SOCK;
#endif
#ifdef S_IFWHT
case S_IFWHT:
- ftwbuf->typeflag = BFTW_WHT;
- break;
+ return BFTW_WHT;
#endif
+
+ default:
+ return BFTW_UNKNOWN;
}
+}
+
+/** Call stat() and use the results. */
+static int ftwbuf_stat(struct BFTW *ftwbuf, struct stat *sb) {
+ int ret = fstatat(ftwbuf->at_fd, ftwbuf->at_path, sb, ftwbuf->at_flags);
+ if (ret != 0) {
+ return ret;
+ }
+
+ ftwbuf->statbuf = sb;
+ ftwbuf->typeflag = bftw_mode_to_typeflag(sb->st_mode);
return 0;
}