All non-programming and programming problems in this assignment are to be done by yourself. Group collaboration is not permitted for this assignment. All homework submissions are to be made via Courseworks. Refer to the homework policy section on the class web site for further details.
Write wtar in C. Your wtar should assume each of its command line arguments is a filename, open that file and write its contents to standard output, in order and preserving the files permissions. Directories are ignored, so there is no recursion.
Use argv[0] (the executable's name) to identify the operation to perform: wtar will archive, wtar-x will extract the archive. Note that wtar-x only input is one archive file. Don't create two executables, just wtar and create a symbolic link ln -s wtar wtar-x.
You don't need to handle command line options like GNU tar does. Assume all command arguments are filenames, if a directory ignore it.
Just handle normal files, you don't need to handle any special files, symbolic links, etc, if you encounter a non-regular file: ignore it and print warning (stderr). If a file is not found, just gracefully ignore it and print a warning in the stderr, but continue processing.
When extracting, don't recreate the original file paths, only extract the files in the current working directory. So, if wtar /bin/ls /usr/bin/other it would extract both files into the current working directory, ignoring their original paths.
When extracting you only have to preserve owner, group and other permission bits.
You do need to handle the case where no files are given on the command line. In this case tar should read from standard input.
Notice that you don't have to handle redirection operators like <, >, and >>, or globbing operators like *, ?, and []. Redirection and globbing are done by the shell on behalf of every program run by that shell.
Example Run
# Archive Files: # # Following will archive the contents of the student directory. # user> wtar /home/student/* > student.wtar # # Extract archive: # # user> wtar-x student.wtar # user> ls -la # -rw-r--r-- 1 student studentgrp 235 Sep 3 13:04 file1.txt # -rwxr-xr-x 1 student studentgrp 303 Sep 3 13:04 binary_ls # ... # user>
Write a simple shell in C. Your shell should read a
line from standard input, parse the line to get the command
and its arguments, fork, and exec
the command. Your shell should wait for commands to finish,
and should exit when it receives the command
exit.
When executing a command, the shell should first look for
the command in the current directory, and, if not found,
search the directories defined in a special variable,
path.
Using the system function is not allowed,
as it just invokes the system's /bin/sh shell
to do all the work.
You may assume command line arguments are separated by whitespace. Don't do anything special for backslashes, quotes, ampersands or other characters that are ``special'' in other shells. Note that this means commands in your shell will not be able to operate on filenames with spaces in them!
You may set a reasonable maximum on the number of command line arguments, but your shell should handle input lines of any length.
The executable file for your shell should be named sh. When testing, make sure you execute your sh and not /bin/sh.
The path variable holds a list of possible paths in which to search for executables. The list of paths is empty by default. You should implement a builtin command to control this variable: path [+|- /some/dir]
path (without arguments) displays all the entries in the list separated by colons, e.g. "/bin:/usr/bin".
path + /some/dir appends the given pathname to the path list.
path - /some/dir removes the given pathname from the path list.
errno variable (see the function's man page to find out if it does), you should use the result of strerror(errno) as part of your error message.
As far as system calls are concerned, you will want to use one of the
mechanisms described in Reporting Errors or Error Reporting.