Created
January 29, 2020 18:02
-
-
Save hasufell/2cb00888c5b4a6fa380f2a5fd2bd54b1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <sys/types.h> | |
#include <dirent.h> | |
#include <stddef.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
int main() { | |
DIR *dir = opendir("/home"); | |
if (readdir(dir) == NULL) { | |
printf("d is NULL"); | |
exit(1); | |
} | |
if (closedir(dir) != 0) { | |
printf("closedir failed"); | |
exit(1); | |
} | |
struct dirent *d = readdir(dir); | |
if (d == NULL) { | |
printf("d is NULL"); | |
exit(1); | |
} else { | |
printf("%s", d->d_name); | |
} | |
d = readdir(dir); | |
if (d == NULL) { | |
printf("d is NULL"); | |
exit(1); | |
} else { | |
printf("%s", d->d_name); | |
} | |
return 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment