MaxenceBacquet 6 年之前
父节点
当前提交
65e4a2c2d3
共有 1 个文件被更改,包括 8 次插入2 次删除
  1. 8 2
      myls.c

+ 8 - 2
myls.c

@@ -22,7 +22,10 @@ int printDir(struct dirent** contentsDir, char* path, int nbFile,
 
     //Affiche les fichiers
     while(j < nbFile){
-        stat(contentsDir[j]->d_name, &info);
+        if(stat(contentsDir[j]->d_name, &info) == ERR){
+            addperror("Erreur stat");
+            return -1;
+        }
         /*switch(info.st_mode){
             case S_IRUSR:
                 permission[1] = 'r';
@@ -82,7 +85,10 @@ void ls(int argc, char* argv[]){
     //Time to display
     for(i = 1; i < argc; i++){
         if(argv[i][0] != '-'){
-            stat(argv[i], &info);
+            if(stat(argv[i], &info) == ERR){
+                addperror("Erreur stat");
+                return;
+            }
             if(S_ISDIR(info.st_mode)){
                 nbFile = scandir(argv[i], &contentsDir, 0, alphasort);
                 if (nbFile < 0) {