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

Showing the changes to src (1 of 1 file). Show all

Unified · Split

src/pt2_diskop.c+8−38
@@ -142,7 +142,6 @@ static int8_t findFirst(fileEntry_t *searchRec) · 141 unmodified lines
142#else142#else
143 struct dirent *fData;143 struct dirent *fData;
144 struct stat st;144 struct stat st;
145 int64_t fSize;
146#endif145#endif
147 146
148 searchRec->nameU = NULL; // this one must be initialized147 searchRec->nameU = NULL; // this one must be initialized
@@ -172,26 +171,12 @@ static int8_t findFirst(fileEntry_t *searchRec) · 23 unmodified lines
172 return LFF_SKIP;171 return LFF_SKIP;
173 172
174 searchRec->filesize = 0;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)178 searchRec->isDir = !!(st.st_mode & S_IFDIR);
180 {179 searchRec->filesize = ((int64_t)st.st_size > INT32_MAX) ? -1 : (int32_t)st.st_size;
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 }
195 }180 }
196#endif181#endif
197 182
@@ -226,7 +211,6 @@ static int8_t findNext(fileEntry_t *searchRec) · 28 unmodified lines
226#else211#else
227 struct dirent *fData;212 struct dirent *fData;
228 struct stat st;213 struct stat st;
229 int64_t fSize;
230#endif214#endif
231 215
232 searchRec->nameU = NULL; // important216 searchRec->nameU = NULL; // important
@@ -252,26 +236,12 @@ static int8_t findNext(fileEntry_t *searchRec) · 19 unmodified lines
252 return LFF_SKIP;236 return LFF_SKIP;
253 237
254 searchRec->filesize = 0;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)243 searchRec->isDir = !!(st.st_mode & S_IFDIR);
260 {244 searchRec->filesize = ((int64_t)st.st_size > INT32_MAX) ? -1 : (int32_t)st.st_size;
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 }
275 }245 }
276#endif246#endif
277 247

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