Question: In this assignment, you will write a small library that parses files and directory structures to list files and directory contents recursively in a tree
In this assignment, you will write a small library 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.
Below is the boiler code:

Below is the code that contains TODO comments that should be completed:

Feel free to number the TODO comments in your answer to avoid writing out all of this code. Thanks
*include "libtree, h" 1 * Convenient macro to get the length of an dprintf(...) can be used like printf to print diagnostic messages in the debug build. Does compilation determined by a compile-time pebug macro. $/ vifdef bEBUG tdefine dprintf(...) fprintfistderr, _ VA_ARGS _ \#define dprintf(..) ((void) ) tendif /* 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 ioeans 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 int print path infolstruct fileinfo finfol. static char *mode_string(mode_t mode); static int read_file_list(Dip *dirg, struct fileinfo **file_list, size_t *file_count); static void free_file__list(struct fileinfo **file_list, size_t file_count]; static int filecmp\{void const *lhhs, void const *rhs); static int depth: static struct tree_options opts; static int cur_dir= AT_FDCWD; / Here are our two main functions. tree_print is the externaliy linked function, accessible to extern int treeprint(char const *jath, struct tree_options opts); static int tree_print_recurseistruct fileinfo finfoli; tree_print(char const *path, struct tree_options opts) opts = opts; depth =0; depth =0 : struct fileinfo finfo: if ([finfo,path = strdup (path) )== NULL) goto exit; f. Istatat(cur_dir, path, (finfo.st), NT_SYMLINK_NOFOLLOW) = = -1) goto exit; freelfinfo. path): return errno? 1:0
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
