This commit is contained in:
JunkJumper 2020-09-10 11:48:43 +02:00
parent f53bb0c3cf
commit b46206336c

View File

@ -4,7 +4,7 @@
* @ Copyright: Creative Common 4.0 (CC BY 4.0)
* @ Create Time: 04-09-2020 11:43:11
* @ Modified by: JunkJumper
* @ Modified time: 10-09-2020 10:47:45
* @ Modified time: 10-09-2020 11:46:13
* @ Description: code c produisant le même résultat qu'un ls.
*/
@ -12,13 +12,17 @@
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <stdlib.h>
#include <unistd.h>
int main(int argc, char *argv[])
{
DIR *dir;
struct dirent *entry;
struct stat attribut;
int lesAtt;
if (argc != 2)
{
@ -27,10 +31,17 @@ int main(int argc, char *argv[])
}
dir = opendir(argv[1]);
chdir(argv[1]);
entry = readdir(dir);
printf("%-10s %-5s %-30s\n", "Inode", "Type", "Nom de Fichier");
printf("%-10s %-5s %-30s %-30s\n", "Inode", "Type", "Nom de Fichier", "Stats inode");
while(entry != NULL) {
printf("%-10d %-5d %-30s\n", (int)entry->d_ino, entry->d_type, entry->d_name);
lesAtt = stat(entry->d_name, &attribut);
if(lesAtt == -1) {
perror("Échec stat");
exit(2);
}
printf("%-10d %-5d %-30s %-30d\n", (int)entry->d_ino, entry->d_type, entry->d_name, attribut.st_ino);
entry = readdir(dir);
}
closedir(dir);