pete > courses > CS 315 Fall 26 > Assignment 1


Assignment 1

If any of this is unclear, please get in touch with me ASAP. There are definitely things in the course I want you to struggle with. I absolutely do NOT want you struggling with understanding my expectations.

In this assignment, you will implement basic functionality of the ls program. Specifically, your implementation must work the same as the real ls program under the following scenarios:

You will have to experiment and/or research how ls behaves in these cases so that you can duplicate it.

The logic itself is not terribly complicated; I expect and intend much of your time will be spent reading man pages and acclimating yourself to maneuvering around Linux and C.

Goals

The goals of this assignment are for you to

New Mechanics

You might find these useful in this assignment.

New functions

Separately, the stat(2) manpage lists the fields of the struct stat populated by stat(3p); the inode(7) manpage goes into further detail. Note that file permissions (eg, read, write, execute) are called the "mode".

Behavioral requirements

You will produce a source file, myls.c, that implements the required logic. When compiled and run with no arguments, it should list all non-hidden files in the current directory. When supplied with a list of arguments, it should behave as ls does: for all non-directories, list the files themselves; for all directories, list the contents; error if a file doesn’t exist. Ordering of the output is at your discretion (you will notice that, in a listing with both files and directories, ls will show all files first and then all directories, regardless of the order they appeared on the command-line; you do not need to do this). Unless a single filename exceeds 80 characters, the output of your program should not exceed 80 columns.

Furthermore, your ls program must accept the -a and -l options. When provided with the -a option, your program should list all files in the directories given, including hidden files. When provided with the -l option, your program should provide detailed information about each file, one file per line, just as the standard ls program does.

When provided with the -l option, your implementation does not need to print the "total ##" line that the standard version of ls prints.

You must use getopt(3) to parse command-line arguments.

You do not need to match the spacing of the real ls.

You may assume that a path will never exceed PATH_MAX bytes in length, even though this isn’t really true.

Deliverable requirements

Style requirements

Your code must exhibit:

Hard Mode [optional!]

Here are some optional features you might consider adding. You do not need to implement any of them to receive credit, and I strongly recommend you do not try unless and until you have finished the rest of the requirements and wish to explore further This list is provided solely as idea fodder if you want to go above and beyond.

Submission Process

Your submission files should be in a git repository on basin in this directory:

/home/<username>/<secret>/assignment1

Email me when you want feedback, with a description of the type of feedback you would like, and the identifier of the revision on which you would like feedback.

Last modified: