2017-08-22 01:41:15 +02:00
|
|
|
#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;
|
|
|
|
|
2017-08-30 00:15:50 +02:00
|
|
|
dirp = opendir("/usr/glenda");
|
2017-08-22 01:41:15 +02:00
|
|
|
if(dirp != NULL)
|
2017-08-30 00:15:50 +02:00
|
|
|
printf("opendir(/usr/glenda): done\n");
|
2017-08-22 01:41:15 +02:00
|
|
|
else
|
2017-08-30 00:15:50 +02:00
|
|
|
printf("opendir(/usr/glenda): failed\n");
|
2017-08-22 01:41:15 +02:00
|
|
|
|
|
|
|
while (dirp) {
|
|
|
|
errno = 0;
|
|
|
|
if ((dp = readdir(dirp)) != NULL) {
|
2017-08-30 00:15:50 +02:00
|
|
|
if (strcmp(dp->d_name, "readme.acme") == 0) {
|
2017-08-22 01:41:15 +02:00
|
|
|
if(dp->d_type == DT_REG){
|
|
|
|
++i;
|
|
|
|
printf("FOUND! ");
|
|
|
|
}
|
|
|
|
}
|
2017-08-30 00:15:50 +02:00
|
|
|
if (strcmp(dp->d_name, "tmp") == 0) {
|
2017-08-22 01:41:15 +02:00
|
|
|
if(dp->d_type == DT_DIR){
|
|
|
|
++i;
|
|
|
|
printf("FOUND! ");
|
|
|
|
}
|
|
|
|
}
|
2017-08-30 00:15:50 +02:00
|
|
|
printf("%s: %s\n", dp->d_name, dp->d_type == DT_DIR ? "directory" : "regular file");
|
2017-08-22 01:41:15 +02:00
|
|
|
if(i == 2){
|
|
|
|
closedir(dirp);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
} else {
|
2017-08-30 00:15:50 +02:00
|
|
|
printf("readdir returned NULL before finding both readme.acme and tmp/\n");
|
2017-08-22 01:41:15 +02:00
|
|
|
if (errno == 0) {
|
|
|
|
closedir(dirp);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
closedir(dirp);
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 3;
|
|
|
|
}
|