[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: |
Fri, 2 May 2008 09:25:28 +0200 |
User-agent: |
KMail/1.5.4 |
Eric Blake wrote:
> > 4. EOF when reading the first byte, no error, and offset > 0.
> > Return value was 0 and is now -1.
>
> I still think this case is like getdelim failing at EOF, particularly since...
>
> >
> > 5. EOF when reading the first byte, no error, and offset == 0.
> > Return value is -1.
>
> offset should not need to be consulted if the stream is already at EOF.
One can argue that getndelim2 should behave like this, and if I had designed
it, maybe I would have specified it like you say.
But when you look at the history ("gitk lib/getndelim2.c",
"gitk lib/getnline.c") you see that since the function getstr() was
introduced in coreutils in 1995, with an offset argument, it returned 0
in case 4.
+ if (c == EOF ...)
+ {
+ /* Return partial line, if any. */
+ if (read_pos == *lineptr)
+ return -1;
+ else
+ break;
+ }
To treat case 4 differently, the line in the middle would have to read
if (read_pos == *lineptr + offset)
I'm hesitating to change an interface that exists for 13 years, saying
that it is a "bug fix". Even if the number of users of this interface
(with offset > 0) appears to be zero (according to Google codesearch).
> Yes, we can revert this part of the patch, and improve the documentation. It
> also means we need to beef up the testcase to stress all 5 conditions, and
> ensure we don't regress from the more-heavily documented interface.
I'll do that on Sunday, if you are not quicker than me.
Bruno