-
-
Save akkijp/fd2a4e4c5d8f93b4c35f to your computer and use it in GitHub Desktop.
lsコマンドを作ってみた
This file contains hidden or 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 <stdio.h> | |
#include <stdlib.h> | |
#include <sys/types.h> | |
#include <dirent.h> | |
static void do_ls(char *path){ | |
DIR *d; | |
struct dirent *ent; | |
d = opendir(path); | |
if(!d){ | |
perror(path); | |
exit(1); | |
} | |
while( (ent = readdir(d)) ){ | |
printf("%s\n", ent->d_name); | |
} | |
closedir(d); | |
} | |
int main(int argc, char *argv[]){ | |
int i; | |
if(argc < 2){ | |
fprintf(stderr, "%s: no arguments\n", argv[0]); | |
exit(1); | |
} | |
for(i=1; i<argc; i++){ | |
do_ls(argv[i]); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment