Read N Characters Given Read4 II - Call multiple times
The API:int read4(char *buf)
reads4
characters at a time from a file.
The return value is the actual number of characters read. For example, it returns 3 if there is only 3 characters left in the file.
By using the read4 API, implement the functionint read(char *buf, int n)
that reads n characters from the file.
分析
缓冲区size 4,每次read4读入。
如果readpos == writepos 又要读入buffer,同时readpos writepos重设
如果writepos ==0 (read4 return0)没有数据了返回
Last updated