Question: Problem 2 ( 5 0 points ) Modify the rio _ read ( ) function to treat the rio _ buf as a circular buffer

Problem 2(50 points)
Modify the rio_read() function to treat the rio_buf as a circular buffer when the user decides
to do so:
The call to rio_read() must remain the same:
rio_read (rio_t * rp, char * usrbuf, size_t n)
When the circular use is enabled, rio_read() copies bytes from rio_buf to the caller's
usrbuf. When the last byte from rio_buf has been given to the user, the NEXT CALL to
rio_read() copies bytes from the beginning of rio_buf instead of refilling rio_buf with a
read from the file.
Write a function rio_circular (rio_t * rp, int v) to select circular use or not:
'rio_circular' (rp,?bar(1)) enables circular use
rio_circular (rp,0) disables circular use
Make the necessary modifications to rio_read() and elsewhere but do not change its
arguments.
For Reference
int open(const char *pathname, int flags, mode_t mode);
ssize_t read(int fd, void *buf, size_t count);
off_t Iseek(int fd, off_t offset, int whence);
O_APPEND enables append mode: all write operations write the data the end the file,
extending it, regardless of the C
#define RIO_BUFSIZE 8192
typedef strct {
int rio_fd;
int rio_cnt;
char *rio_bufptr; r
char rio_buf [RIO_BUFSIZE];
} rio_t;
void rio_readinitb(rio_t * rp, int fd)
1
rp->rio_fd = fd;
rp-rio_cnt =0;
rp->rio_bufptr = rp->rio_buf;
}
ssize_t rio_read (rio_t * rp, char * usrbuf, size_t n)
1
int cnt;
if (rp->rio_cnt =0)
1
1** refill if buf is empty */
rp->rio_cnt = read(rp->rio_fd, rp->rio_buf, sizeof (rp->rio_buf));
if (rp->rio_cnt 0) return -1 ;
else if (rp--riocnt=0) return 0;I***EOF***?
else rp->rio_bufptr = rp->rio_buf; ??** reset buffer ptr ***?
}
/* Copy min(n, rp->rio_cnt) bytes from internal buf to user buf ***?
cnt =n;
if (rp rio_cnt =rpp+=-= Modify the rio _read() function to treat the rio_buf as a circular buffer when the user decides to do so:
The call to rio read() must remain the same:
rio read (riot * rp, char * usrbuf, size_t n)
When the circular use is enabled, rio_read() copies bytes from rio_buf to the caller's usrbuf. When the last byte from rio_buf has been given to the user, the NEXT CALL to rio_read() copies bytes from the beginning of rio_buf instead of refilling rio_buf with a read from the file.
Write a function rio_circular (rio_t * rp, int v) to select circular use or not:
W"rio circular (rp,1) enables circular use
rio circular (rp,O) disables circular use
Make the necessary modifications to rio_read() and elsewhere but do not change its arguments.
 Problem 2(50 points) Modify the rio_read() function to treat the rio_buf

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 Databases Questions!