Thanks to Annatar for noticing this problem.
Unified · Split
| @@ -142,7 +142,6 @@ static int8_t findFirst(fileEntry_t *searchRec) · 141 unmodified lines | ||
| 142 | 142 | #else |
| 143 | 143 | struct dirent *fData; |
| 144 | 144 | struct stat st; |
| 145 | − int64_t fSize; | |
| 146 | 145 | #endif |
| 147 | 146 | |
| 148 | 147 | searchRec->nameU = NULL; // this one must be initialized |
| @@ -172,26 +171,12 @@ static int8_t findFirst(fileEntry_t *searchRec) · 23 unmodified lines | ||
| 172 | 171 | return LFF_SKIP; |
| 173 | 172 | |
| 174 | 173 | searchRec->filesize = 0; |
| 175 | − searchRec->isDir = (fData->d_type == DT_DIR) ? true : false; | |
| 174 | + searchRec->isDir = false; | |
| 176 | 175 | |
| 177 | − if (fData->d_type == DT_UNKNOWN || fData->d_type == DT_LNK) | |
| 176 | + if (stat(fData->d_name, &st) == 0) | |
| 178 | 177 | { |
| 179 | − if (stat(fData->d_name, &st) == 0) | |
| 180 | − { | |
| 181 | − fSize = (int64_t)st.st_size; | |
| 182 | − searchRec->filesize = (fSize > INT32_MAX) ? -1 : (fSize & 0xFFFFFFFF); | |
| 183 | − | |
| 184 | − if ((st.st_mode & S_IFMT) == S_IFDIR) | |
| 185 | − searchRec->isDir = true; | |
| 186 | − } | |
| 187 | − } | |
| 188 | − else if (!searchRec->isDir) | |
| 189 | − { | |
| 190 | − if (stat(fData->d_name, &st) == 0) | |
| 191 | − { | |
| 192 | − fSize = (int64_t)st.st_size; | |
| 193 | − searchRec->filesize = (fSize > INT32_MAX) ? -1 : (fSize & 0xFFFFFFFF); | |
| 194 | − } | |
| 178 | + searchRec->isDir = !!(st.st_mode & S_IFDIR); | |
| 179 | + searchRec->filesize = ((int64_t)st.st_size > INT32_MAX) ? -1 : (int32_t)st.st_size; | |
| 195 | 180 | } |
| 196 | 181 | #endif |
| 197 | 182 | |
| @@ -226,7 +211,6 @@ static int8_t findNext(fileEntry_t *searchRec) · 28 unmodified lines | ||
| 226 | 211 | #else |
| 227 | 212 | struct dirent *fData; |
| 228 | 213 | struct stat st; |
| 229 | − int64_t fSize; | |
| 230 | 214 | #endif |
| 231 | 215 | |
| 232 | 216 | searchRec->nameU = NULL; // important |
| @@ -252,26 +236,12 @@ static int8_t findNext(fileEntry_t *searchRec) · 19 unmodified lines | ||
| 252 | 236 | return LFF_SKIP; |
| 253 | 237 | |
| 254 | 238 | searchRec->filesize = 0; |
| 255 | − searchRec->isDir = (fData->d_type == DT_DIR) ? true : false; | |
| 239 | + searchRec->isDir = false; | |
| 256 | 240 | |
| 257 | − if (fData->d_type == DT_UNKNOWN || fData->d_type == DT_LNK) | |
| 241 | + if (stat(fData->d_name, &st) == 0) | |
| 258 | 242 | { |
| 259 | − if (stat(fData->d_name, &st) == 0) | |
| 260 | − { | |
| 261 | − fSize = (int64_t)st.st_size; | |
| 262 | − searchRec->filesize = (fSize > INT32_MAX) ? -1 : (fSize & 0xFFFFFFFF); | |
| 263 | − | |
| 264 | − if ((st.st_mode & S_IFMT) == S_IFDIR) | |
| 265 | − searchRec->isDir = true; | |
| 266 | − } | |
| 267 | − } | |
| 268 | − else if (!searchRec->isDir) | |
| 269 | − { | |
| 270 | − if (stat(fData->d_name, &st) == 0) | |
| 271 | − { | |
| 272 | − fSize = (int64_t)st.st_size; | |
| 273 | − searchRec->filesize = (fSize > INT32_MAX) ? -1 : (fSize & 0xFFFFFFFF); | |
| 274 | − } | |
| 243 | + searchRec->isDir = !!(st.st_mode & S_IFDIR); | |
| 244 | + searchRec->filesize = ((int64_t)st.st_size > INT32_MAX) ? -1 : (int32_t)st.st_size; | |
| 275 | 245 | } |
| 276 | 246 | #endif |
| 277 | 247 | |