ref: f6f4566fb88896f4449d897fcd4e246cd42117da
parent: 28e1bab1f15ab3c2daff639b3962985fbd4bc240
author: Olav Sørensen <olav.sorensen@live.no>
date: Mon Apr 18 13:32:15 EDT 2022
Made some code even more POSIX compliant Thanks to Annatar for noticing this problem.
--- a/src/pt2_diskop.c
+++ b/src/pt2_diskop.c
@@ -142,7 +142,6 @@
#else
struct dirent *fData;
struct stat st;
- int64_t fSize;
#endif
searchRec->nameU = NULL; // this one must be initialized
@@ -172,27 +171,13 @@
return LFF_SKIP;
searchRec->filesize = 0;
- searchRec->isDir = (fData->d_type == DT_DIR) ? true : false;
+ searchRec->isDir = false;
- if (fData->d_type == DT_UNKNOWN || fData->d_type == DT_LNK)
+ if (stat(fData->d_name, &st) == 0)
{
- if (stat(fData->d_name, &st) == 0)
- {
- fSize = (int64_t)st.st_size;
- searchRec->filesize = (fSize > INT32_MAX) ? -1 : (fSize & 0xFFFFFFFF);
-
- if ((st.st_mode & S_IFMT) == S_IFDIR)
- searchRec->isDir = true;
- }
+ searchRec->isDir = !!(st.st_mode & S_IFDIR);
+ searchRec->filesize = ((int64_t)st.st_size > INT32_MAX) ? -1 : (int32_t)st.st_size;
}
- else if (!searchRec->isDir)
- {
- if (stat(fData->d_name, &st) == 0)
- {
- fSize = (int64_t)st.st_size;
- searchRec->filesize = (fSize > INT32_MAX) ? -1 : (fSize & 0xFFFFFFFF);
- }
- }
#endif
if (searchRec->filesize < -1)
@@ -226,7 +211,6 @@
#else
struct dirent *fData;
struct stat st;
- int64_t fSize;
#endif
searchRec->nameU = NULL; // important
@@ -252,26 +236,12 @@
return LFF_SKIP;
searchRec->filesize = 0;
- searchRec->isDir = (fData->d_type == DT_DIR) ? true : false;
+ searchRec->isDir = false;
- if (fData->d_type == DT_UNKNOWN || fData->d_type == DT_LNK)
+ if (stat(fData->d_name, &st) == 0)
{
- if (stat(fData->d_name, &st) == 0)
- {
- fSize = (int64_t)st.st_size;
- searchRec->filesize = (fSize > INT32_MAX) ? -1 : (fSize & 0xFFFFFFFF);
-
- if ((st.st_mode & S_IFMT) == S_IFDIR)
- searchRec->isDir = true;
- }
- }
- else if (!searchRec->isDir)
- {
- if (stat(fData->d_name, &st) == 0)
- {
- fSize = (int64_t)st.st_size;
- searchRec->filesize = (fSize > INT32_MAX) ? -1 : (fSize & 0xFFFFFFFF);
- }
+ searchRec->isDir = !!(st.st_mode & S_IFDIR);
+ searchRec->filesize = ((int64_t)st.st_size > INT32_MAX) ? -1 : (int32_t)st.st_size;
}
#endif