- A simple UNIX program that copies one file from its source file to a destination file (see Fig. 3). The program has minimal functionality and even worse error reporting.
copyfile abc xyz
Figure 3:
A simple program to copy a file.
|
- The copy loop. It starts by trying to read in 4 KB of data to buffer. It does this by calling the library procedure read, which actually invokes the read system call.
- The call to write outputs the buffer to the destination file.
- When the entire file has been processed, the first call beyond the end of file will return 0 to rd_count which will make it exit the loop. At this point the two files are closed and the program exits with a status indicating normal termination.
Cem Ozdogan
2010-05-05