Hi Jeremie,
Jeremie Courreges-Anglas wrote on Sun, Jul 23, 2017 at 12:43:14AM +0200:
> getline(3) and perror(3) are in posix, but fgetln(3) and err(3) come
> from 4.4BSD (according to their manpage). We should probably keep the
> example code posix-compliant.
Paul Janzen asked me the same question in private mail,
and i answered as follows:
Here is my six cents:
(1) We should promote <err.h> functions even for portable
applications because they are better than the alternatives
and providing fallback implementations in a portable
application is trivial (see mandoc).
(2) EXAMPLES should promote best practices, not portability purism,
even in pages for standardized functions. We write OpenBSD
manuals, not POSIX manuals. (Of course, that doesn't imply
we should be imprecise about which part of the functionality
of the function *itself* that is documented in the page is
standard and which parts are extensions.)
(3) The focus of this part of the example is how to check for
errors, not what to do in that case.
if (ferror(fp)) err(...) is quite comprehensible generically
even if you don't know what exactly err(...) is.
(4) If you want to know details about err(...), refer to err(3).
(5) EXAMPLES are code snippets, almost always incomplete.
An additional line "#include <err.h>" would seem more
like a distraction than like a helpful addition.
(6) We already use err(3) in getopt(3), malloc(3), strdup(3),
wcsdup(3), which are all POSIX.
Yours,
Ingo
>> Index: getdelim.3
>> ===================================================================
>> RCS file: /cvs/src/lib/libc/stdio/getdelim.3,v
>> retrieving revision 1.4
>> diff -u -p -r1.4 getdelim.3
>> --- getdelim.3 4 Apr 2016 19:23:52 -0000 1.4
>> +++ getdelim.3 22 Jul 2017 08:51:16 -0000
>> @@ -124,7 +124,7 @@ while ((linelen = getline(\*[Am]line, \*
>>
>> free(line);
>> if (ferror(fp))
>> - perror("getline");
>> + err(1, "getline");
>> .Ed
>> .Sh ERRORS
>> .Bl -tag -width [EOVERFLOW]