Aggiornamento alla versione reale
[gapil.git] / listati / my_ls.c
1 #include <sys/types.h>
2 #include <sys/stat.h>
3 #include <dirent.h>        /* directory */
4 #include <stdlib.h>        /* C standard library */
5 #include <unistd.h>
6
7 /* computation function for DirScan */
8 int do_ls(struct dirent * direntry);
9 /* main body */
10 int main(int argc, char *argv[]) 
11 {
12     ...
13     if ((argc - optind) != 1) {          /* There must be remaing parameters */
14         printf("Wrong number of arguments %d\n", argc - optind);
15         usage();
16     }
17     DirScan(argv[1], do_ls);
18     exit(0);
19 }
20 /*
21  * Routine to print file name and size inside DirScan
22  */
23 int do_ls(struct dirent * direntry) 
24 {
25     struct stat data;
26
27     stat(direntry->d_name, &data);                          /* get stat data */
28     printf("File: %s \t size: %d\n", direntry->d_name, data.st_size);
29     return 0;
30 }