Add files attributes TDM
This commit is contained in:
parent
9af65d2e27
commit
499f97fced
4 changed files with 56 additions and 0 deletions
BIN
content/progsys/TDM_7-attributs_fichiers/files/tdm7.pdf
Normal file
BIN
content/progsys/TDM_7-attributs_fichiers/files/tdm7.pdf
Normal file
Binary file not shown.
15
content/progsys/TDM_7-attributs_fichiers/index.md
Normal file
15
content/progsys/TDM_7-attributs_fichiers/index.md
Normal file
|
@ -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.
|
BIN
content/progsys/TDM_7-attributs_fichiers/src/myls.bin
Executable file
BIN
content/progsys/TDM_7-attributs_fichiers/src/myls.bin
Executable file
Binary file not shown.
41
content/progsys/TDM_7-attributs_fichiers/src/myls.c
Normal file
41
content/progsys/TDM_7-attributs_fichiers/src/myls.c
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue