MaxenceBacquet 6 年 前
コミット
08ea5ed87b
1 ファイル変更3 行追加17 行削除
  1. 3 17
      myls.c

+ 3 - 17
myls.c

@@ -54,20 +54,12 @@ int printDir(struct dirent** contentsDir, char* path, int nbFile,
 }
 
 void ls(int argc, char* argv[]){
-    char buffer[BUFFER_SIZE];
-    char path[BUFFER_SIZE];
     struct dirent** contentsDir;
     struct stat info;
-    int i = 1, j = 0, displayed = 0, nbFile, opt;
+    int i = 1, displayed = 0, nbFile, opt;
     boolean hiddenFile = false;
     boolean checksubDir = false;
 
-    //Recuperation chemin actuel
-    if (getcwd(buffer, sizeof (buffer)) == NULL) {
-        addperror("Erreur getcwd()");
-        return;
-    }
-
     //Gestion des options
     while((opt = getopt(argc, argv, "aR")) != ERR){
         switch(opt){
@@ -96,10 +88,7 @@ void ls(int argc, char* argv[]){
                     return;
                 }
                 printf("%s : \n\n", argv[i]);
-                strcpy(path, buffer);
-                strcat(path, "/");
-                strcat(path, contentsDir[j]->d_name);
-                displayed = printDir(contentsDir, path, nbFile, hiddenFile);
+                displayed = printDir(contentsDir, argv[i], nbFile, hiddenFile);
             }
             else{
                 printf("%d  %ld  %s\n", info.st_mode, info.st_size, argv[i]);
@@ -114,10 +103,7 @@ void ls(int argc, char* argv[]){
             addperror("Erreur scandir()");
             return;
         }
-        strcpy(path, buffer);
-        strcat(path, "/");
-        strcat(path, contentsDir[j]->d_name);
-        displayed = printDir(contentsDir, path, nbFile, hiddenFile);
+        displayed = printDir(contentsDir, ".", nbFile, hiddenFile);
     }
 
     printf("%d   %d\n", hiddenFile, checksubDir);