Created
December 25, 2013 19:11
-
-
Save luqmaan/e9b0269754b32d3f2ab3 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
#include <stdio.h> | |
#include <stdlib.h> | |
#include <sys/stat.h> | |
#include <sys/types.h> | |
#include <sys/dir.h> | |
int main(int argc, char **argv) { | |
DIR* midir; | |
if ((midir=opendir(argv[1])) < 0) { | |
perror("\nError en opendir\n"); | |
exit(-1); | |
} | |
struct dirent* info_archivo; | |
struct stat fileStat; | |
while ((info_archivo = readdir(midir)) != NULL) { | |
stat(info_archivo->d_name, &fileStat); | |
printf((S_ISDIR(fileStat.st_mode)) ? "d" : "-"); | |
printf((fileStat.st_mode & S_IRUSR) ? "r" : "-"); | |
printf((fileStat.st_mode & S_IWUSR) ? "w" : "-"); | |
printf((fileStat.st_mode & S_IXUSR) ? "x" : "-"); | |
printf((fileStat.st_mode & S_IRGRP) ? "r" : "-"); | |
printf((fileStat.st_mode & S_IWGRP) ? "w" : "-"); | |
printf((fileStat.st_mode & S_IXGRP) ? "x" : "-"); | |
printf((fileStat.st_mode & S_IROTH) ? "r" : "-"); | |
printf((fileStat.st_mode & S_IWOTH) ? "w" : "-"); | |
printf((fileStat.st_mode & S_IXOTH) ? "x" : "-"); | |
printf(" %s", info_archivo->d_name); | |
printf("\n"); | |
} | |
closedir(midir); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ouptut
ls -l