-
-
Save boryspoplawski/72d43b53551ef64ef5ddddf17d65ff4c 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 <dirent.h> | |
#include <err.h> | |
#include <errno.h> | |
#include <fcntl.h> | |
#include <stdio.h> | |
#include <string.h> | |
#include <sys/mman.h> | |
#include <sys/stat.h> | |
#include <sys/types.h> | |
#include <sys/wait.h> | |
#include <unistd.h> | |
void dirread(const char *dname) { | |
DIR *dp; | |
struct dirent *de; | |
dp = opendir(dname); | |
while (1) { | |
errno = 0; | |
de = readdir(dp); | |
if (!de) { | |
if (errno) { | |
printf("ERROR: readdir: %s\n", strerror(errno)); | |
_exit(1); | |
} else { | |
break; | |
} | |
} | |
printf("GOT: %s\n", de->d_name); | |
} | |
closedir(dp); | |
} | |
int main(int argc, char *argv[]) { | |
int p = fork(); | |
if (p < 0) { | |
puts("FORK"); | |
return 1; | |
} else if (p == 0) { | |
dirread("/proc"); | |
} else { | |
wait(&p); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment