Aggiornamento note copyright
[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 /* computation function for dir_scan */
7 int do_ls(struct dirent * direntry);
8 /* main body */
9 int main(int argc, char *argv[]) 
10 {
11     ...
12     if ((argc - optind) != 1) {          /* There must be remaing parameters */
13         printf("Wrong number of arguments %d\n", argc - optind);
14         usage();
15     }
16     dir_scan(argv[1], do_ls);
17     exit(0);
18 }
19 /*
20  * Routine to print file name and size inside dir_scan
21  */
22 int do_ls(struct dirent * direntry) 
23 {
24     struct stat data;
25
26     stat(direntry->d_name, &data);       /* get stat data */
27     printf("File: %s \t size: %d\n", direntry->d_name, data.st_size);
28     return 0;
29 }