Homework 4, Tee Time

This homework is worth 10 points.

Implement the tee program.

Goals

When you finish this homework you should:

Assignment

Do problem 4-1 on page 87: The tee command reads its standard input until end-of-file, writing a copy of the input to standard output and to the file named in its command-line argument. Implement mytee, your version of tee using I/O system calls. By default, tee overwrites any existing file with the given name. Implement the -a command line option (mytee -a file), which causes mytee to append text to the end of a file if it already exists.

Please call your program mytee.

Running the following

who | mytee -a testFile
date | mytee -a testFile
uptime | mytee -a testFile
should
  1. Output the results of each of these commands to the screen
  2. Produce a file with the results of all three commands in the file.
If run without the -a option, only the last output should be in the file.

You may not use iostreams (C++) or stdio (c) to accomplish this task. It must be done with open, read, write, close and lseek. You may use iostreams or stdio for debugging, for error messages and for help functions.

Your files should be created readable and writable for the user, and readable for group and other.

When you are finished email a compressed tar file containing your code, a Makefile and a README file to your instructor. Please do not include executable or object files in your submission.