summaryrefslogtreecommitdiffstats
path: root/bftw.c
diff options
context:
space:
mode:
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;
}