Question: Problem 1 . A certain file foo contains the ASCII text string This file contains 2 8 bytes.. That is , the bytes of the

Problem 1. A certain file foo contains the ASCII text string "This file contains 28 bytes.". That is, the bytes of the file, viewed as 8-bit integers, contain the values 0x54,0x65,0x73,0x74, and 0x20, etc.
a. Suppose a program opens foo for reading and writing (file descriptor fd is returned), and it contains a declaration char buf[30];
The program then does the following.
if ((rv = read(fd,buf,10))<0){...handle error... } if ((rv = write(fd,buf,10))<0){... handle error... }
Assuming both calls return 10, what does the file contain after this code runs?
b. Suppose the same program next calls lseek(fd,0,SEEK_SET) to rewind the file offset to the beginning, and then does the following:
if ((rv = read(fd,buf,30))<0){...handle error... } strcpy(buf,"That"); if ((rv = write(fd,buf,rv))<0){... handle error... }
What does the file now contain?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!