[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: getndelim2 improvements
From: |
Bruno Haible |
Subject: |
Re: getndelim2 improvements |
Date: |
Thu, 1 May 2008 15:39:42 +0200 |
User-agent: |
KMail/1.5.4 |
Eric Blake wrote:
> It also fixes a bug where when the stream is at EOF, sometimes the
> function returned 0 and sometimes -1; the patch makes sure EOF always
> results in -1 (similar to the Posix 200x specification of getdelim always
> returning -1 at EOF).
>
> - return bytes_stored;
> + return bytes_stored ? bytes_stored : -1;
I disagree with this part of your patch and with your explanation.
There are 5 ways how getndelim2 can terminate:
1. There are errors. Return value is -1.
2. At least one byte is read and stored, and no error. Return value is > 0.
3. At least one byte is read, but not stored (due to nmax), and no error.
Return value was 0 and is now -1.
4. EOF when reading the first byte, no error, and offset > 0.
Return value was 0 and is now -1.
5. EOF when reading the first byte, no error, and offset == 0.
Return value is -1.
The change in cases 3 and 4
- is IMO not appropriate, since the inability to _extend_ the current
line (due to nmax or EOF) does not mean that the part of the line that
was read so far should be ignored,
- should have been mentioned in NEWS as a behaviour change of getndelim,
- cannot be justified by pointing to getdelim in POSIX, because getdelim
does not have the nmax and offset arguments.
I am in favour of reverting this change, and adding comments to clarify the
5 possible outcomes of getndelim2.
Bruno
- Re: getndelim2 improvements,
Bruno Haible <=