Explanation of Solution
Modified code from figure 10.5:
The modified code for “cpfile.c” is shown below:
//Include header file
#include <stdio.h>
#include "csapp.h"
//Main function
int main(int argc, char* argv[])
{
//Declare "int" variable
int n;
//Create the object for read buffer of type
rio_t rio;
//Declare "MAXLINE" for memory
char buf[MAXLINE];
/* Check the command line arguments. If the command line contains two argument, then copy the infile to standard output */
if (argc == 2)
{
/* Store the descriptor number in "fd" */
int fd = Open(argv[1], O_RDONLY, 0);
while ((n = Rio_readn(fd, buf, MAXBUF)) != 0)
Rio_writen(STDOUT_FILENO, buf, n);
//Exit the process
exit(0);
}
/* Otherwise copy a text file from standard input to...
Want to see the full answer?
Check out a sample textbook solutionChapter 10 Solutions
EBK COMPUTER SYSTEMS
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY