History

Made some code even more POSIX compliant

Thanks to Annatar for noticing this problem.

Olav Sørensen committed 4 years ago

Commit f6f45661 parent 28e1bab1 file · +8 −38Browse files

Unified · Split

src/pt2_diskop.c+8−38
@@ -142,7 +142,6 @@ static int8_t findFirst(fileEntry_t *searchRec) · 141 unmodified lines
142142 #else
143143 struct dirent *fData;
144144 struct stat st;
145− int64_t fSize;
146145 #endif
147146
148147 searchRec->nameU = NULL; // this one must be initialized
@@ -172,26 +171,12 @@ static int8_t findFirst(fileEntry_t *searchRec) · 23 unmodified lines
172171 return LFF_SKIP;
173172
174173 searchRec->filesize = 0;
175− searchRec->isDir = (fData->d_type == DT_DIR) ? true : false;
174+ searchRec->isDir = false;
176175
177− if (fData->d_type == DT_UNKNOWN || fData->d_type == DT_LNK)
176+ if (stat(fData->d_name, &st) == 0)
178177 {
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;
195180 }
196181 #endif
197182
@@ -226,7 +211,6 @@ static int8_t findNext(fileEntry_t *searchRec) · 28 unmodified lines
226211 #else
227212 struct dirent *fData;
228213 struct stat st;
229− int64_t fSize;
230214 #endif
231215
232216 searchRec->nameU = NULL; // important
@@ -252,26 +236,12 @@ static int8_t findNext(fileEntry_t *searchRec) · 19 unmodified lines
252236 return LFF_SKIP;
253237
254238 searchRec->filesize = 0;
255− searchRec->isDir = (fData->d_type == DT_DIR) ? true : false;
239+ searchRec->isDir = false;
256240
257− if (fData->d_type == DT_UNKNOWN || fData->d_type == DT_LNK)
241+ if (stat(fData->d_name, &st) == 0)
258242 {
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;
275245 }
276246 #endif
277247

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t