qa: add test for opendir/readdir/closedir in newlib
This commit is contained in:
parent
63b227be55
commit
97c4c2bccb
51
qa/lib/newlib/102-files.c
Normal file
51
qa/lib/newlib/102-files.c
Normal file
@ -0,0 +1,51 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
int i = 0;
|
||||
DIR *dirp;
|
||||
struct dirent *dp;
|
||||
|
||||
dirp = opendir("/");
|
||||
if(dirp != NULL)
|
||||
printf("opendir(/): done\n");
|
||||
else
|
||||
printf("opendir(/): failed\n");
|
||||
|
||||
while (dirp) {
|
||||
errno = 0;
|
||||
if ((dp = readdir(dirp)) != NULL) {
|
||||
if (strcmp(dp->d_name, "README.md") == 0) {
|
||||
if(dp->d_type == DT_REG){
|
||||
++i;
|
||||
printf("FOUND! ");
|
||||
}
|
||||
}
|
||||
if (strcmp(dp->d_name, "sys") == 0) {
|
||||
if(dp->d_type == DT_DIR){
|
||||
++i;
|
||||
printf("FOUND! ");
|
||||
}
|
||||
}
|
||||
printf("%s: %s\n", dp->d_name, dp->d_type == DT_DIR ? "directory" : "regular");
|
||||
if(i == 2){
|
||||
closedir(dirp);
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
printf("readdir returned NULL\n");
|
||||
if (errno == 0) {
|
||||
closedir(dirp);
|
||||
return 1;
|
||||
}
|
||||
closedir(dirp);
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
return 3;
|
||||
}
|
@ -37,6 +37,7 @@
|
||||
"030-pause.c",
|
||||
"100-files.c",
|
||||
"101-files.c",
|
||||
"102-files.c",
|
||||
"200-signals.c",
|
||||
"201-signals.c",
|
||||
"202-signals.c",
|
||||
@ -81,8 +82,10 @@
|
||||
"000-hello.c",
|
||||
"010-fork.c",
|
||||
"020-waitpid.c",
|
||||
"030-pause.c",
|
||||
"100-files.c",
|
||||
"101-files.c",
|
||||
"102-files.c",
|
||||
"200-signals.c",
|
||||
"201-signals.c",
|
||||
"202-signals.c",
|
||||
|
Loading…
Reference in New Issue
Block a user