Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Task 2: lsal in C (40pt.) Simply: We need to construct a program that will list all the files and directories in a location via

Task 2: lsal in C (40pt.) Simply: We need to construct a program that will list all the files and directories in a location via terminal. In this task, you will implement a special version of the ls program, called lsal. In particular, you need to write a C program that accepts a command-line argument and behaves almost like ls -al, printing details of all files. The followings will explain the expected behavior:

Expected behavior - If an argument is provided, it can be either a file name or a directory name. If the argument is a directory name, you will list all files/directories inside it. Otherwise, you only list the corresponding file.

- Note that "." or ".." are directories as well and therefore your program should work for them too.

- If an argument is not provided your program will list the working directory (same as ".").

- In order to retrieve and inspect the file information, you need to carefully study the inode's manual.

- Only list the regular files and directories. Skip other types such as links, etc. See inode for how to test the file type.

- Your output must be exactly the same as in ls. Therefore, you can use diff as you have seen in previous test scripts to fully test your program before submission. This is of course true for directories that contain regular files and directories only. For example, your output would not list a symlink while ls does.

- Make sure that you also replicate the behavior of ls if file/directory cannot be found by printing the same error message to stderr. Hints: Some of the system calls that may be useful for this Task include opendir, readdir, lstat, getpwuid, and getgrgid

Make sure you pass the full pathname (absolute/relative) as argument to functions such as lstat.

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

Oracle Database Foundations Technology Fundamentals For IT Success

Authors: Bob Bryla

1st Edition

0782143725, 9780782143720

Students also viewed these Databases questions