3 Lists the contents of the directory or directories named on
4 the command line, or of the current directory if none are
7 By default, only the name of each file is printed. If "-l" is
8 given as the first argument, the type, size, and inumber of
9 each file is also printed. This won't work until project 4. */
16 list_dir (const char *dir, bool verbose)
18 int dir_fd = open (dir);
21 printf ("%s: not found\n", dir);
27 char name[READDIR_MAX_LEN];
31 printf (" (inumber %d)", inumber (dir_fd));
34 while (readdir (dir_fd, name))
42 snprintf (full_name, sizeof full_name, "%s/%s", dir, name);
43 entry_fd = open (full_name);
51 printf ("%d-byte file", filesize (entry_fd));
52 printf (", inumber %d", inumber (entry_fd));
55 printf ("open failed");
62 printf ("%s: not a directory\n", dir);
68 main (int argc, char *argv[])
73 if (argc > 1 && !strcmp (argv[1], "-l"))
81 success = list_dir (".", verbose);
85 for (i = 1; i < argc; i++)
86 if (!list_dir (argv[i], verbose))
89 return success ? EXIT_SUCCESS : EXIT_FAILURE;