Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Problem 2 ( 5 0 points ) Modify the rio _ read ( ) function to treat the rio _ buf as a circular buffer
Problem points
Modify the rioread function to treat the riobuf as a circular buffer when the user decides
to do so:
The call to rioread must remain the same:
rioread riot rp char usrbuf, sizet
When the circular use is enabled, rioread copies bytes from riobuf to the caller's
usrbuf. When the last byte from riobuf has been given to the user, the NEXT CALL to
rioread copies bytes from the beginning of riobuf instead of refilling riobuf with a
read from the file.
Write a function riocircular riot rp int to select circular use or not:
'riocircular' rp enables circular use
riocircular disables circular use
Make the necessary modifications to rioread and elsewhere but do not change its
arguments.
For Reference
int openconst char pathname int flags, modet mode;
ssizet readint fd void buf sizet count;
offt Iseekint fd offt offset, int whence;
OAPPEND enables append mode: all write operations write the data the end the file,
extending it regardless of the
#define RIOBUFSIZE
typedef strct
int riofd;
int riocnt;
char riobufptr; r
char riobuf RIOBUFSIZE;
riot;
void rioreadinitbriot rp int fd
rpriofd fd;
rpriocnt ;
rpriobufptr rpriobuf;
ssizet rioread riot rp char usrbuf, sizet
int cnt;
if rpriocnt
refill if buf is empty
rpriocnt readrpriofd rpriobuf, sizeof rpriobuf;
if riocnt return ;
else if riocnt return ;
else rpriobufptr rpriobuf; reset buffer ptr
Copy min rpriocnt bytes from internal buf to user buf
cnt ;
if riocnt Modify the rio read function to treat the riobuf 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, sizet n
When the circular use is enabled, rioread copies bytes from riobuf to the caller's usrbuf. When the last byte from riobuf has been given to the user, the NEXT CALL to rioread copies bytes from the beginning of riobuf instead of refilling riobuf with a read from the file.
Write a function riocircular riot rp int v to select circular use or not:
Wrio circular rp enables circular use
rio circular rpO disables circular use
Make the necessary modifications to rioread and elsewhere but do not change its arguments.
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