Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Part 4 : write code and submit it to the autograder This is a code mimic the linux cp command. Here are the requirements. 1
Part : write code and submit it to the autograder
This is a code mimic the linux cp command. Here are the requirements.
This program works by first prompting the user for the name of the source file and destination file. It shall include all necessary error checking, including ensuring that the source file exists. The main function should return upon successful execution and return upon error condition.
Hint: int openconst char pathname int flags, modet mode;
The program needs to pass several test cases set in the autograder.
It is a common practice to test the code using shell script in software engineering. We are not required to write test cases. Instead, students can submit the code to run the test in AutoGrader.
For learning purposes, I attach an example for your reference:
Test case example
#binbash
echo Hi this is the source file to be used" source.txt echo "This is an existing file to be used" existing.txt
echo "Test case : destination file does not exist" if mycopy source.txt source.txtbak;
then
echo "Using diff command to see if two files are same"
diff source.txt source.txtbak else
echo "Something went wrong"; fi
echo "Test case : destination file already exist" if mycopy source.txt existing.txt;
then
echo "Using diff command to see if two files are same"
diff source.txt existing.txt else
echo "something went wrong" fi
echo "Test case : source file does not exist" if mycopy noexistingfile destinationfile; then
echo "Using diff to compare two files"
diff noexistingfile destinationfile else
echo "Something went wrong" fi
After editing the above file, say, saving it as testScript, use the following command to make the file executable by all: chmod x testScript
Then you will be able to type the following command line to execute the commands in the script in order to test your program: testScript
Extra work not required
Once students correctly coded and tested the program, run the program using a utility that can traces system calls. Linux systems provide the strace utility, and macOS systems use the dtruss
command. The dtruss command, which actually is a front end to dtrace, requires admin privileges, so it must be run using sudo. These tools can be used as follows assume that the name of the executable file is FileCopy:
a Linux: strace FileCopy
b Macos: sudo dtruss FileCopy
c Windows: Need to find a similar one as debugger
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