Question: 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
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 then does the following. Assume buf is a 30-byte array of char. 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 1seek (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
a Suppose a program opens foo for reading and writing file descriptor fd is returned and then does t... View full answer
Get step-by-step solutions from verified subject matter experts
