In this assignment you will write programs that will transfer a file from one directory to another using a named pipe.
Part 0:
Make a directory called assign3 under your cs3733 directory.
Get a copy of the files restart.c and restart.h.
These can be gotten from the
USP programs web page for Appendix B.
In Parts 1 and 2 below you will be using the programs int the restart library.
Create a makefile that uses separate compilation to compile your programs
and link them to the restart library. Your programs should include
restart.h. You should not modify either restart.h or
restart.c.
Part 1:
Write a program called pipereceiver that takes one command line
parameter, the name of a named pipe. It starts by reading two lines from the
named pipe. The first line is the name of a file and the second is the
size of the file represented as ASCII digits. Each of these is terminated
by a newline, not a string terminator. Use the readline function from
the restart library to read in these lines. Use a buffer of size 1024 for the
filename and a buffer of size 64 for the size of the file. If either of these
does not fit, print an appropriate error message to standard output and exit
the program.
If all is OK, create a new file of with the given name in the current directory. Be careful that the name of the file does not contain the newline symbol. If the file already exists or some other error occurs when you open the file, print an appropriate error message and exit the program. Otherwise, attempt to read the bytes from the pipe until the required number of bytes have been read. Use the same buffer of size 1024 that you used for the filename. These bytes should be stored in the file that you created. If you cannot successfully read the appropriate number of bytes from the pipe or an error occurs writing to the file, print an appropriate error message and exit the program.
Close the file. If everything was successful, print a message containing the name of the file and its size and exit the program.
Test the program in two windows. Pick a file to send. Use ls-l to find out the size of the file. In the first window, redirect standard input to go to the named pipe. Type the name of a file you are going to send and the size of the file. From another window, cat the file you are sending, redirecting the output of cat to go to the pipe. Use diff to make sure the files are identical.
Part 2:
Write a program called pipesender that takes two command line
arguments, the name of a file and the name of a named pipe. This program
should send the file to the named pipe so that pipereceiver can
receive it. You will have to send the name of the file and its size
before sending the file.
You may assume that the name of the file contains only a file name with no path specification. To test the program, run pipesender in one directory and pipereceiver in another. The named pipe that you use can be in either of these directories or in another directory. In any case you will need to correctly specify the named pipe on the command line for each program.
Handing in your program:
Do the following to test your program and create output to hand in: