Answered step by step
Verified Expert Solution
Question
1 Approved Answer
1. Complete a function dupFile(const char* name1, const char* name2) in the attached program. template prog.c After its completion, name2 file will have duplicated
1. Complete a function "dupFile(const char* name1, const char* name2)" in the attached program. template "prog.c" After its completion, name2 file will have duplicated contents from name1 file contents. For example, if name1 file contains the following 9 characters: ABCDMHJWP Then, after its execution the name2 file will contain 18 characters: ABCDMHJWPABCDMHJWP You can only make use of the following system calls in the function implementation: open() read() Iseek() write) close() You have to complete the function definition in the attached "prog.c" file which includes main() calling dupFile("data1.txt", "data2 txt"). "data1.txt" file is also attached. Your function should use the buffer size of 10 bytes in reading and writing. If you use the other buffer sizes, you will get a penalty of 50% of the entire grade "prog.c* CODE BELOW PLEASE DO NOT CHANGE ANY OF THE CODE UNLESS IT HAS // /* dupFile - dupFile namel name2 */ #include #include #include #include #include // !!! DO NOT CHNAGE BUFSIZE #define BUFSIZE 10 #define PERM 0644 /* size of chunk to be read */ /* file permission for new file */ /* dupFile namel name2 */ // name2 file will have duplicated contents from namel file contents int dupFile( const char *namel, const char *name2) { int infile-1, outfile=-1; ssize_t nread, nwrite; char buffer[BUFSIZE]; if( (infile open(namel, O_RDONLY) ) return (-1); == -1) if( ( outfile = open(name2, O_WRONLY O_CREAT | O_TRUNC, PERM) ) == -1) return (-1); // // You need to read the contents of infile and copy to outfile (2 times!) copying! //// } close(infile); close (outfile); return 1; Fill out this part!! - main loop(s) for duplicate int main(int argc, char *argv) { } int main(int argc, char *argv) { if (argc!=3) { printf("Usage: dupFiles file1 file2 "); exit(-1); } } int retcode=-1; retcode = dupFile(argv[1], argv[2]);
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