Opened 4 years ago

#367 new defect

return value of read() in text mode

Reported by: KO Myung-Hun Owned by:
Priority: normal Milestone: new
Component: libc Version: 0.6.6
Severity: normal Keywords:



A similar problem is described in the kLIBC FAQ page,

However, some different problems from that may occur. In general, if read() returns a smaller value than the requested size, then it's assumed that end-of-file was reached.

But, some datum of a file still remain if read()ing a part of file contains \r\n pairs.

As well as, after writing some datum including cr-lf pairs to a file, datum read up to the same size as those datum will be different from those datum.

This is becuase read() reads a file into a buffer up to the requested size and returns a number of cr-lf converted characters of the buffer. So if cr-lf pairs exist in the buffer, the return value becomes smaller than the requested size.

To avoid this, I suggest to read() a file into a buffer until a number of cr-lf converted characters is the requested size.

This will reduce the cr-lf confusions in text mode.

Attachments (1)

read-1.c (891 bytes) - added by KO Myung-Hun 4 years ago.

Download all attachments as: .zip

Change History (1)

Changed 4 years ago by KO Myung-Hun

Attachment: read-1.c added


Note: See TracTickets for help on using tickets.