Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this assignment, you will write a small library in C that parses files and directory structures to list files and directory contents recursively in

In this assignment, you will 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. Write the code where TODO comments are present. Observe the example output below:

$./tree -pugs /usr/share/man/en [drwxr-xr-x root root 66] /usr/share/man/en [drwxr-xr-x root root 148] man2 [-rw-r--r-- root root 2407] close.2.gz [-rw-r--r-- root root 1808] getdomainname.2.gz [-rw-r--r-- root root 7736] getrlimit.2.gz [-rw-r--r-- root root 4852] madvise.2.gz [-rw-r--r-- root root 5949] mount.2.gz [-rw-r--r-- root root 1445] sysinfo.2.gz [-rw-r--r-- root root 1962] umask.2.gz [drwxr-xr-x root root 158] man3 [-rw-r--r-- root root 2141] encrypt.3.gz [-rw-r--r-- root root 2004] fclose.3.gz [-rw-r--r-- root root 2143] fflush.3.gz [-rw-r--r-- root root 2214] lockf.3.gz [-rw-r--r-- root root 2700] rand.3.gz [-rw-r--r-- root root 3157] strtok.3.gz [-rw-r--r-- root root 1359] toupper.3.gz [-rw-r--r-- root root 1502] updwtmp.3.gz [drwxr-xr-x root root 21] man4 [-rw-r--r-- root root 10229] st.4.gz [drwxr-xr-x root root 23] man5 [-rw-r--r-- root root 4761] utmp.5.gz [drwxr-xr-x root root 64] man7 [-rw-r--r-- root root 3165] environ.7.gz [-rw-r--r-- root root 4731] hier.7.gz [-rw-r--r-- root root 4278] suffixes.7.gz

Here is the boiler plate code:

image text in transcribed

Here is the code with TODO comments that should be completed:

image text in transcribedimage text in transcribedimage text in transcribedFeel free to number that 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; 134 gbrief Helper function that prints formatted output of the modestring, username, groupname, file size, and link target for links)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts of Database Management

Authors: Philip J. Pratt, Joseph J. Adamski

7th edition

978-1111825911, 1111825912, 978-1133684374, 1133684378, 978-111182591

Students also viewed these Databases questions