Re: Bug in external editor code



On Sat, 26 January 12:44 Peter Bloomfield wrote:
> Well, this was educational for me! From glibc-2.2.4/stdio/fgets.c:
> 
> /* Reads characters from STREAM into S, until either a newline character
>    is read, N - 1 characters have been read, or EOF is seen.  Returns
>    the newline, unlike gets.  Finishes by appending a null character and
>    returning S.  If EOF is seen before any characters have been written
>    to S, the function returns NULL without appending the null character.
>    If there is a file error, always return NULL.  */
> char *
> fgets (s, n, stream)
> 
> So it's documented...in the source! The man page reads:
> 
>        fgets()  reads  in  at  most one less than size characters
>        from stream and stores them into the buffer pointed to  by
>        s.  Reading stops after an EOF or a newline.  If a newline
>        is read, it is stored into the buffer.  A '\0'  is  stored
>        after the last character in the buffer.
> 
> Does `last character' imply that there is at least one character in the 
> buffer? If so, the man page is consistent with what fgets really does, but 
> it's easily misread as meaning `A '\0' is stored after any characters'.

If you go to http://www.opengroup.org/ and register, you can download or have 
online access to the Single Unix Spec v2 for free.  I find this a much better 
source of what an implementation is supposed to do rather than man pages which 
tend to describe what a particular implementation does.

Brian



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]