Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a copy program similar to Cp in UNIX. An execution of your program will take two command-line arguments. It should then try to open
Write a copy program similar to Cp in UNIX. An execution of your program will take two command-line arguments. It should then try to open the file named by the first command-line argument. If successful, it should try to create a file with the name given in the second command-line argument, but without clobbering (deleting) any existing file by that name. If again successful, it should loop through the contents of the first file, writing them to the second file. Finally, it should close both files and print out the total number of bytes copied. Be sure to check for any errors in opening, creating, reading and writing the files, and print an appropriate error message if one is encountered. An execution of your program should look like this $./mycp file1 file2 copied 1512 byte:s You will implement this program using the POSIX API on Linux. Your code should use a buffer size of 1024 bytes. Use the low level file 1/O API for reading/writing the files (i.e. open, close, read, and write). This API is also referred to as the OPEN family of system calls Use the stdio formatted I/O API (i.e. the printf family) for writing the number of bytes copied and reporting errors. Use the man page entries for function prototypes, details on how to use each system call, as well as all of the necessary #include files. Remember that most system calls are in section 2 or 3 of the man pages (i.e. use man 2 write not man write to get information about the write system ca). Use the diff utility to compare the input and output files of your program The program should compile without warnings when compiled with "-Wall". Error messages should be output to stderr using fprintf. You can treat a "short write" (where the number of bytes returned by write is fewer than the number of bytes requested to write) as an error You do not need to check for errors from close You should submit your source code file and a short writeup in pdf format that includes a description of what you did and the compilation and execution output from your program. Test your program with both a file under 1 KB and one over 1 KB
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started