Skip to content

Instantly share code, notes, and snippets.

@hasufell
Created January 29, 2020 18:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hasufell/2cb00888c5b4a6fa380f2a5fd2bd54b1 to your computer and use it in GitHub Desktop.
Save hasufell/2cb00888c5b4a6fa380f2a5fd2bd54b1 to your computer and use it in GitHub Desktop.
#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