Browse Source

add stat function (size right)

MaxenceBacquet 6 năm trước cách đây
mục cha
commit
b0df8e69a7
1 tập tin đã thay đổi với 12 bổ sung1 xóa
  1. 12 1
      myls.c

+ 12 - 1
myls.c

@@ -1,7 +1,10 @@
 #define _DEFAULT_SOURCE
 
 #include <dirent.h>
+#include <sys/types.h>
+#include <sys/stat.h>
 #include <unistd.h>
+#include <string.h>
 #include "parser.h"
 #include "error.h"
 #include "color.h"
@@ -10,6 +13,8 @@
 void lsBasics(int argc, char* argv[]){
     char buffer[BUFFER_SIZE];
     struct dirent** contentsDir;
+    struct stat info;
+    char path[BUFFER_SIZE];
     int i = 0, nbFile;
 
     //Recuperation chemin actuel
@@ -33,7 +38,13 @@ void lsBasics(int argc, char* argv[]){
 
     //Affiche les fichiers
     while(i < nbFile){
-        printf("%s\n", contentsDir[i]->d_name);
+        strcpy(path, buffer);
+        strcat(path, "/");
+        strcat(path, contentsDir[i]->d_name);
+        printf("%s\n", path);
+        if(stat(path, &info) == ERR)
+            addperror("Erreur stat");
+        printf("%d  %ld  %s\n", info.st_mode, info.st_size, contentsDir[i]->d_name);
         i++;
     }