Add files attributes TDM

This commit is contained in:
Yorick Barbanneau 2018-10-18 23:41:12 +02:00
parent 9af65d2e27
commit 499f97fced
4 changed files with 56 additions and 0 deletions

View 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.

Binary file not shown.

View 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");
}
}