altri pezzi di codice da aggiungere
[gapil.git] / listati / my_ls.c
diff --git a/listati/my_ls.c b/listati/my_ls.c
new file mode 100644 (file)
index 0000000..1ff634a
--- /dev/null
@@ -0,0 +1,30 @@
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <dirent.h>        /* directory */
+#include <stdlib.h>        /* C standard library */
+#include <unistd.h>
+
+/* computation function for DirScan */
+int do_ls(struct dirent * direntry);
+/* main body */
+int main(int argc, char *argv[]) 
+{
+    ...
+    if ((argc - optind) != 1) {          /* There must be remaing parameters */
+        printf("Wrong number of arguments %d\n", argc - optind);
+        usage();
+    }
+    DirScan(argv[1], do_ls);
+    exit(0);
+}
+/*
+ * Routine to print file name and size inside DirScan
+ */
+int do_ls(struct dirent * direntry) 
+{
+    struct stat data;
+
+    stat(direntry->d_name, &data);                          /* get stat data */
+    printf("File: %s \t size: %d\n", direntry->d_name, data.st_size);
+    return 0;
+}