MCPcopy Create free account
hub / github.com/apache/nuttx / foreach_dirent

Function foreach_dirent

tools/initialconfig.c:391–446  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

389 ****************************************************************************/
390
391static int foreach_dirent(const char *dirpath, direntcb_t cb, void *arg)
392{
393 DIR *dirp;
394 struct dirent *entry;
395 int ret;
396
397 dirp = opendir(dirpath);
398 if (dirp == NULL)
399 {
400 fprintf(stderr, "ERROR: Failed to open directory '%s': %s\n",
401 dirpath, strerror(errno));
402 exit(EXIT_FAILURE);
403 }
404
405 for (; ; )
406 {
407 /* To distinguish between end of stream and error, set
408 * errno to 0 and verify whether its value changed if
409 * readdir returned NULL.
410 */
411
412 errno = 0;
413
414 entry = readdir(dirp);
415 if (entry == NULL && errno != 0)
416 {
417 fprintf(stderr,
418 "ERROR: Failed to read directory '%s' entry: %s\n",
419 dirpath, strerror(errno));
420 closedir(dirp);
421 exit(EXIT_FAILURE);
422 }
423
424 if (entry == NULL)
425 {
426 break;
427 }
428
429 /* Skip over the . and .. hard links */
430
431 if (strcmp(entry->d_name, ".") == 0 ||
432 strcmp(entry->d_name, "..") == 0)
433 {
434 continue;
435 }
436
437 ret = cb(dirpath, entry, arg);
438 if (ret != 0)
439 {
440 break;
441 }
442 }
443
444 closedir(dirp);
445 return ret;
446}
447
448/****************************************************************************

Callers 2

enum_boardsFunction · 0.85
mainFunction · 0.85

Calls 7

opendirFunction · 0.85
fprintfFunction · 0.85
strerrorFunction · 0.85
exitFunction · 0.85
readdirFunction · 0.85
closedirFunction · 0.85
strcmpFunction · 0.50

Tested by

no test coverage detected