/** * @ 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 * @ Modified time: 17-09-2020 10:25:25 * @ Description: code c produisant le même résultat qu'un ls. */ /// M311 - myls #include #include #include #include #include #include #include int main(int argc, char *argv[]) { DIR *dir; struct dirent *entry; struct stat attribut; struct passwd user; int lesAtt; if (argc != 2) { fprintf(stderr, "Syntaxe : %s {le chemin}\n\n", argv[0]); exit(1); } dir = opendir(argv[1]); chdir(argv[1]); entry = readdir(dir); printf("%-10s %-3s %-5s %-15s %-15s %-8s %-13s %-30s \n", "Inode", "RWX", "Type", "Propriétaire", "Group Name", "Size", "Time", "Nom de Fichier"); while(entry != NULL) { lesAtt = stat(entry->d_name, &attribut); if(lesAtt == -1) { perror("Échec stat"); exit(2); } printf("%-10d %-3o %-5d %-15d %-15d %-8d %-13d %-30s\n", (int)entry->d_ino, attribut.st_mode&0777, entry->d_type, attribut.st_uid, attribut.st_gid, attribut.st_size,attribut.st_mtime, entry->d_name); entry = readdir(dir); } closedir(dir); return 0; }