Question: Write a small library in C that parses files and directory structures to list files and directory contents recursively in a tree format, where each

Write a small library in C that parses files and directory structures to list files and directory contents recursively in a tree format, where each subdirectory is indented from the last. You will implement basic sorting and print the file permissions, username, group, and file size. Most of the code is written except for the TODO comments circled in red. Finish the code where TODO comments are shown below. For your answer number TODO 1-8 instead of writing out this entire file. Thanks

Write a small library in C that parses files and directory structures

to list files and directory contents recursively in a tree format, whereeach subdirectory is indented from the last. You will implement basic sortingand print the file permissions, username, group, and file size. Most ofthe code is written except for the TODO comments circled in red.

tdefine arrlen(a) \{sizeof(a) / sizeof (a) ) dprintf(...) can be used like printf to print diagnostic messages in the debug build. Does ifdef Debug \#define dprintf(...) fprintfistderr, __VA_ARGS _ ] telse *define /* We will need to pass around file stat info quite a bit, so let's make a struct for this purpose. struct fileinfo char *pathi struct stat st; * Nore: Notice how all of these functions and file-scope identifiers are declared static. This means they have no linkage. You should read the C language reference documents and the difference /* A few helper functions to break up the program static char *mode_string(mode_t mode): static void free_file_list(struct fileinfo **file_list, size_t file_count): static int filecmp(void const *lhs, void const *rhs); * some file-scoped static int depth: static struct tree_options opts: static int cur_dir=AT_FDCWD; f* Here are our two main functions. tree_print is the externaliy linked function, accessible to static int tree_print_recurse(struct fileinfo finfoli: extern int tree_print(char const *path, struct tree_options opts) opts = opts: depth =0; depth =0 : (lfinfo.path = strdup ( path) ) == NULL) goto exit: fifataticur_dir, path, ( finfo.st), NT_SYMLINK_NOFOLLOW) = = -1) goto exit; freelfinfo.path); 1 4.175

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!