"my ls lai fin TP pas fini"
This commit is contained in:
parent
16a0a5ac18
commit
6084d99ae4
@ -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 11:51:26
|
||||
* @ Modified time: 10-09-2020 12:15:38
|
||||
* @ Description: code c produisant le même résultat qu'un ls.
|
||||
*/
|
||||
|
||||
@ -16,12 +16,14 @@
|
||||
#include <dirent.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <pwd.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
DIR *dir;
|
||||
struct dirent *entry;
|
||||
struct stat attribut;
|
||||
struct passwd user;
|
||||
int lesAtt;
|
||||
|
||||
if (argc != 2)
|
||||
@ -33,7 +35,7 @@ int main(int argc, char *argv[])
|
||||
dir = opendir(argv[1]);
|
||||
chdir(argv[1]);
|
||||
entry = readdir(dir);
|
||||
printf("%-10s %-5s %-30s %-30s\n", "Inode", "Type", "Nom de Fichier", "Nombre de liens durs");
|
||||
printf("%-10s %-10s %-5s %-15s %-15s %-8s %-13s %-30s \n", "Inode", "Permission", "Type", "Propriétaire", "Group Name", "Size", "Time", "Nom de Fichier");
|
||||
while(entry != NULL) {
|
||||
lesAtt = stat(entry->d_name, &attribut);
|
||||
|
||||
@ -41,7 +43,7 @@ int main(int argc, char *argv[])
|
||||
perror("Échec stat");
|
||||
exit(2);
|
||||
}
|
||||
printf("%-10d %-5d %-30s %-30d\n", (int)entry->d_ino, entry->d_type, entry->d_name, attribut.st_nlink);
|
||||
printf("%-10d %-10d %-5d %-15d %-15d %-8d %-13d %-30s\n", (int)entry->d_ino, attribut.st_mode, entry->d_type, attribut.st_uid, attribut.st_gid, attribut.st_size,attribut.st_mtime, entry->d_name);
|
||||
entry = readdir(dir);
|
||||
}
|
||||
closedir(dir);
|
||||
|
Loading…
x
Reference in New Issue
Block a user