Opened 3 years ago

#367 new defect

return value of read() in text mode

Reported by: komh Owned by:
Priority: normal Milestone: new
Component: libc Version: 0.6.6
Severity: normal Keywords:
Cc:

Description

Hi/2.

A similar problem is described in the kLIBC FAQ page, http://trac.netlabs.org/libc/wiki/Faq.

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 komh 3 years ago.
testcase

Download all attachments as: .zip

Change History (1)

Changed 3 years ago by komh

testcase

Note: See TracTickets for help on using tickets.