Answered step by step
Verified Expert Solution
Link Copied!

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 4: write code and submit it to the autograder
This is a code mimic the linux cp command. Here are the requirements.
1. 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 0 upon successful execution and return 1 upon error condition.
Hint: int open(const char *pathname, int flags, mode_t mode);
2. 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
#!/bin/bash
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 1: destination file does not exist" if ./mycopy source.txt source.txt.bak;
then
echo "Using diff command to see if two files are same"
diff source.txt source.txt.bak else
echo "Something went wrong"; fi
echo "Test case 2: 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 3: source file does not exist" if mycopy no_existing_file destination_file; then
echo "Using diff to compare two files"
diff no_existing_file destination_file 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
3. 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Students also viewed these Databases questions