Last active
August 29, 2015 14:18
-
-
Save huseyin/ece853d0983c1ee59370 to your computer and use it in GitHub Desktop.
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
/* | |
* Linux altındaki ls komutuna benzer bir komut | |
*/ | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <sys/stat.h> | |
#include <dirent.h> | |
#define SUCCESS 1 | |
#define FAILURE 0 | |
int main(int argc, char* argv[]) | |
{ | |
DIR* dir; | |
struct dirent* file; | |
struct stat sys_stat; | |
if (argc > 2) | |
{ | |
fprintf(stderr, "Hata: parametre kontrolü\n"); | |
exit(FAILURE); | |
} | |
// | |
dir = opendir(argv[1]); | |
// | |
if (dir) | |
{ | |
while ((file = readdir(dir)) != NULL) | |
{ | |
stat(file->d_name, &sys_stat); | |
fprintf(stdout, "\033[1m%s\n", file->d_name); | |
} | |
} | |
else | |
{ | |
exit(SUCCESS); | |
} | |
printf("\033[0m"); | |
closedir(dir); | |
return EXIT_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment