diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2009-09-30 15:15:08 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2009-09-30 15:15:08 +0200 |
commit | 5632ddb849821bf8c4fac9f4aa8c4779575eef97 (patch) | |
tree | c0f5cdeabec71de882f7d6dcbfffc0daeb0c961a /lib/Utils/xfuncs.cpp | |
parent | 0a901ba3e651a70984e980f61619b005031a71f0 (diff) | |
download | abrt-5632ddb849821bf8c4fac9f4aa8c4779575eef97.tar.gz abrt-5632ddb849821bf8c4fac9f4aa8c4779575eef97.tar.xz abrt-5632ddb849821bf8c4fac9f4aa8c4779575eef97.zip |
fix all instances of dent->d_type == DT_REG checks
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'lib/Utils/xfuncs.cpp')
-rw-r--r-- | lib/Utils/xfuncs.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/Utils/xfuncs.cpp b/lib/Utils/xfuncs.cpp index f447b8f4..d256c195 100644 --- a/lib/Utils/xfuncs.cpp +++ b/lib/Utils/xfuncs.cpp @@ -286,3 +286,22 @@ void xunlink(const char *pathname) if (unlink(pathname)) perror_msg_and_die("can't remove file '%s'", pathname); } + +/* Just testing dent->d_type == DT_REG is wrong: some filesystems + * do not report the type, they report DT_UNKNOWN for every dirent + * (and this is not a bug in filesystem, this is allowed by standards). + */ +int is_regular_file(struct dirent *dent, const char *dirname) +{ + if (dent->d_type == DT_REG) + return 1; + if (dent->d_type != DT_UNKNOWN) + return 0; + + char *fullname = xasprintf("%s/%s", dirname, dent->d_name); + struct stat statbuf; + int r = lstat(fullname, &statbuf); + free(fullname); + + return r == 0 && S_ISREG(statbuf.st_mode); +} |