]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
dirent-util: get rid of stat_mode_to_dirent_type()
authorLennart Poettering <lennart@poettering.net>
Thu, 7 Oct 2021 20:23:35 +0000 (22:23 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 7 Oct 2021 21:13:03 +0000 (23:13 +0200)
Apparently glibc already has a helper for this. (Not in the man pages
for Linux, but FreeBSD does document these cryptic helpers, and its
exported by glibc. That should be good enough for us.)

src/basic/dirent-util.c
src/basic/dirent-util.h
src/basic/recurse-dir.c

index a70871b33dac991c46da9fc5f302798ee5e3249a..366cc077f3e4a4be4ead7b1fc3ff9f098327acde 100644 (file)
@@ -7,18 +7,6 @@
 #include "path-util.h"
 #include "string-util.h"
 
-int stat_mode_to_dirent_type(mode_t mode) {
-        return
-                S_ISREG(mode)  ? DT_REG  :
-                S_ISDIR(mode)  ? DT_DIR  :
-                S_ISLNK(mode)  ? DT_LNK  :
-                S_ISFIFO(mode) ? DT_FIFO :
-                S_ISSOCK(mode) ? DT_SOCK :
-                S_ISCHR(mode)  ? DT_CHR  :
-                S_ISBLK(mode)  ? DT_BLK  :
-                                 DT_UNKNOWN;
-}
-
 static int dirent_ensure_type(DIR *d, struct dirent *de) {
         struct stat st;
 
@@ -36,7 +24,7 @@ static int dirent_ensure_type(DIR *d, struct dirent *de) {
         if (fstatat(dirfd(d), de->d_name, &st, AT_SYMLINK_NOFOLLOW) < 0)
                 return -errno;
 
-        de->d_type = stat_mode_to_dirent_type(st.st_mode);
+        de->d_type = IFTODT(st.st_mode);
 
         return 0;
 }
index 5bbd54df5a8a4beff5b647b4cca7dbb82a9f24f0..c7956e7c1b7819ca839ccd989947151cbefeabae 100644 (file)
@@ -8,8 +8,6 @@
 #include "macro.h"
 #include "path-util.h"
 
-int stat_mode_to_dirent_type(mode_t mode);
-
 bool dirent_is_file(const struct dirent *de) _pure_;
 bool dirent_is_file_with_suffix(const struct dirent *de, const char *suffix) _pure_;
 
index fe34ffbfd407edbe72b2d3a27ab9f6cbc661c9fd..2aabbccadb948c015dd83606c24999e055f11346 100644 (file)
@@ -290,7 +290,7 @@ int recurse_dir(
                         /* Copy over the data we acquired through statx() if we acquired any */
                         if (sx.stx_mask & STATX_TYPE) {
                                 assert(!!subdir == !!S_ISDIR(sx.stx_mode));
-                                de[i]->d_type = stat_mode_to_dirent_type(sx.stx_mode);
+                                de[i]->d_type = IFTODT(sx.stx_mode);
                         }
 
                         if (sx.stx_mask & STATX_INO)