The purpose of this homework is to give the student experience writing a low-level tool in C, using multiple POSIX systems calls, and handling all possible failure conditions.
copyProgram in C
For this assignment, you must write a program in C to copy the contents of one file to another file. Details follow:
cin >>, etc. To print you should use
printf(), fprintf(), snprintf(),etc.
The program opens the
copy src dest
srcfile for reading, creates the
destfile for writing, and copies the contents of
srcfile is not a regular file (i.e., is a directory, special file, symlink, etc.), an error should be printed and
destshould not be created.
destfile already exists, an error should be printed and nothing from
srcshould be copied to
mancommand in a terminal to see how a function behaves and what kind of errors it can return.
Your code should optionally take a
-r flag before the
dest arguments. When
-r is given
src is a directory, then your code creates the directory
dest, and copies every file in
into the new directory
dest. Your code does not have to recurse down any further in the
directory. If there are sub-directories in
src, your code should create those sub-directories in
but it does not have to populate them.
Submit all the code for this homework to
We will grade this exercise according to the following criteria: (25 pts total)