Brilliant, looks good to me, ok nicm
On Sun, Jul 02, 2017 at 06:23:35PM +0200, Ingo Schwarze wrote:
> Hi Nic,
>
> Nicholas Marriott wrote on Sun, Jul 02, 2017 at 08:48:28AM +0100:
>
> > Possibly fgetln(3) CAVEATS could benefit from some of what you have
> > written here, although it is all in the manual already just in several
> > places.
>
> Inspecting the manual page again, i don't think it needs longer
> text. I merely provided more detailed explanations here because i
> got the wrong impression that you were in denial of the potential
> dangers of fgetln(3) - though probably i should have relized how
> implausible that impression was, but anyway.
>
> > Or at least a link to getline(3)?
>
> Indeed. I think that ought to take the form of a mild deprecation
> notice ot the top, though i don't see a need for bold face or any
> kind of strong wording.
>
> While here, let's delete the irrelevant .Xr to putc(3) and instead
> link to fgetc(3) - which is relevant because it is a fundamental
> stdio I/O function and may invalidate the line pointer.
>
> Also, add two lines to the example code for error checking.
> The example is already so long that the two lines don't make it
> much worse, and forgetting error checking is such a common oversight
> for this function that it should not be left out of an example even
> if the example focusses on something else.
>
> OK?
> Ingo
>
>
> Index: fgetln.3
> ===================================================================
> RCS file: /cvs/src/lib/libc/stdio/fgetln.3,v
> retrieving revision 1.17
> diff -u -r1.17 fgetln.3
> --- fgetln.3 13 Jan 2015 14:02:30 -0000 1.17
> +++ fgetln.3 2 Jul 2017 16:03:29 -0000
> @@ -38,6 +38,11 @@
> .Ft char *
> .Fn fgetln "FILE *stream" "size_t *len"
> .Sh DESCRIPTION
> +Using this function is error-prone in multiple ways;
> +consider using the safer and more portable function
> +.Xr getline 3
> +instead.
> +.Pp
> The
> .Fn fgetln
> function returns a pointer to the next line from the stream referenced by
> @@ -103,10 +108,11 @@
> .Xr realloc 3 .
> .Sh SEE ALSO
> .Xr ferror 3 ,
> +.Xr fgetc 3 ,
> .Xr fgets 3 ,
> .Xr fopen 3 ,
> .Xr fparseln 3 ,
> -.Xr putc 3
> +.Xr getline 3
> .Sh HISTORY
> The
> .Fn fgetln
> @@ -139,4 +145,6 @@
> printf("%s\en", buf);
> }
> free(lbuf);
> + if (ferror(fp))
> + err(1, "fgetln");
> .Ed