50 lines
1.1 KiB
C
Raw Normal View History

2020-09-04 12:32:21 +02:00
/**
* @ Author: JunkJumper
* @ Link: https://github.com/JunkJumper
* @ Copyright: Creative Common 4.0 (CC BY 4.0)
* @ Create Time: 04-09-2020 11:43:11
* @ Modified by: JunkJumper
2020-09-10 11:48:43 +02:00
* @ Modified time: 10-09-2020 11:46:13
2020-09-04 12:32:21 +02:00
* @ Description: code c produisant le même résultat qu'un ls.
*/
2020-09-04 11:43:31 +02:00
/// M311 - myls
#include <stdio.h>
2020-09-04 12:32:21 +02:00
#include <sys/types.h>
2020-09-10 11:48:43 +02:00
#include <sys/stat.h>
2020-09-04 12:32:21 +02:00
#include <dirent.h>
#include <stdlib.h>
2020-09-10 11:48:43 +02:00
#include <unistd.h>
2020-09-04 12:32:21 +02:00
int main(int argc, char *argv[])
{
DIR *dir;
struct dirent *entry;
2020-09-10 11:48:43 +02:00
struct stat attribut;
int lesAtt;
2020-09-04 11:43:31 +02:00
2020-09-04 12:32:21 +02:00
if (argc != 2)
{
fprintf(stderr, "Syntaxe : %s {le chemin}\n\n", argv[0]);
exit(1);
}
dir = opendir(argv[1]);
2020-09-10 11:48:43 +02:00
chdir(argv[1]);
2020-09-04 12:32:21 +02:00
entry = readdir(dir);
2020-09-10 11:48:43 +02:00
printf("%-10s %-5s %-30s %-30s\n", "Inode", "Type", "Nom de Fichier", "Stats inode");
2020-09-04 12:32:21 +02:00
while(entry != NULL) {
2020-09-10 11:48:43 +02:00
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);
2020-09-04 12:32:21 +02:00
entry = readdir(dir);
}
closedir(dir);
2020-09-10 10:48:09 +02:00
return 0;
2020-09-04 12:32:21 +02:00
}