diff --git a/content/progsys/TDM_7-attributs_fichiers/files/tdm7.pdf b/content/progsys/TDM_7-attributs_fichiers/files/tdm7.pdf new file mode 100644 index 0000000..c35bb3c Binary files /dev/null and b/content/progsys/TDM_7-attributs_fichiers/files/tdm7.pdf differ diff --git a/content/progsys/TDM_7-attributs_fichiers/index.md b/content/progsys/TDM_7-attributs_fichiers/index.md new file mode 100644 index 0000000..57512c5 --- /dev/null +++ b/content/progsys/TDM_7-attributs_fichiers/index.md @@ -0,0 +1,15 @@ +--- +title: "TDM7 : les attibuts de fichiers" +date: 2018-10-16 +categories: ["Programmation système", "TD machine"] +--- + +[Télécharger]( files/tdm7.pdf ) les questions. + +## Question 1 + +[Voir]( src/myls.c ) mon code C + +J'ai choisi d'utiliser l'operateur ternaire pour afficher les différents +éléments. S'il y a des cas ou il peut complexifier la lecture du code, je le +trouve très adapté à la situation. diff --git a/content/progsys/TDM_7-attributs_fichiers/src/myls.bin b/content/progsys/TDM_7-attributs_fichiers/src/myls.bin new file mode 100755 index 0000000..14ca661 Binary files /dev/null and b/content/progsys/TDM_7-attributs_fichiers/src/myls.bin differ diff --git a/content/progsys/TDM_7-attributs_fichiers/src/myls.c b/content/progsys/TDM_7-attributs_fichiers/src/myls.c new file mode 100644 index 0000000..eb31fcd --- /dev/null +++ b/content/progsys/TDM_7-attributs_fichiers/src/myls.c @@ -0,0 +1,41 @@ +#include +#include +#include +#include + +int main (int argc, char **argv){ + int i; + struct stat statbuf; + for (i = 1; i < argc; i++) { + if (stat(argv[i], &statbuf) < 0) { + perror("Unable to get stats"); + continue; + } + printf("%s", S_ISDIR(statbuf.st_mode) ? "d" : (S_ISLNK(statbuf.st_mode) ? "l" : "_")); + printf("%s", (statbuf.st_mode & S_IRUSR) ? "r" : "-"); + printf("%s", (statbuf.st_mode & S_IWUSR) ? "w" : "-"); + printf("%s", (statbuf.st_mode & S_IXUSR) ? "x" : "-"); + + printf("%s", (statbuf.st_mode & S_IRGRP) ? "r" : "-"); + printf("%s", (statbuf.st_mode & S_IWGRP) ? "w" : "-"); + printf("%s", (statbuf.st_mode & S_IXGRP) ? "x" : "-"); + + printf("%s", (statbuf.st_mode & S_IROTH) ? "r" : "-"); + printf("%s", (statbuf.st_mode & S_IWOTH) ? "w" : "-"); + printf("%s", (statbuf.st_mode & S_IXOTH) ? "x" : "-"); + + printf("\t"); + + printf("%ld\t", statbuf.st_nlink); + + printf("%d ", statbuf.st_uid); + printf("%d ", statbuf.st_gid); + + printf("\t"); + printf("%ld", statbuf.st_size); + + printf("\t"); + printf("%s", argv[i]); + printf("\n"); + } +}