* [PATCH 0/2] fopencookie.3: Fix EXAMPLES section @ 2020-09-07 10:21 Alejandro Colomar 2020-09-07 10:21 ` [PATCH 1/2] fopencookie.3: printf()'s .* expects an int; cast accordingly Alejandro Colomar 2020-09-07 10:21 ` [PATCH 2/2] fopencookie.3: Fix bugs in example Alejandro Colomar 0 siblings, 2 replies; 5+ messages in thread From: Alejandro Colomar @ 2020-09-07 10:21 UTC (permalink / raw) To: mtk.manpages; +Cc: linux-man, Alejandro Colomar *** BLURB HERE *** Hi Michael, I fixed a few bugs in the example program. Testing the patch cover-letter now :) Cheers, Alex Alejandro Colomar (2): fopencookie.3: printf()'s .* expects an int; cast accordingly fopencookie.3: Fix bugs in example man3/fopencookie.3 | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) -- 2.28.0 ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/2] fopencookie.3: printf()'s .* expects an int; cast accordingly 2020-09-07 10:21 [PATCH 0/2] fopencookie.3: Fix EXAMPLES section Alejandro Colomar @ 2020-09-07 10:21 ` Alejandro Colomar 2020-09-07 10:31 ` Michael Kerrisk (man-pages) 2020-09-07 10:21 ` [PATCH 2/2] fopencookie.3: Fix bugs in example Alejandro Colomar 1 sibling, 1 reply; 5+ messages in thread From: Alejandro Colomar @ 2020-09-07 10:21 UTC (permalink / raw) To: mtk.manpages; +Cc: linux-man, Alejandro Colomar Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com> --- man3/fopencookie.3 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/man3/fopencookie.3 b/man3/fopencookie.3 index 472a7f3d2..5394ce4a5 100644 --- a/man3/fopencookie.3 +++ b/man3/fopencookie.3 @@ -438,7 +438,7 @@ main(int argc, char *argv[]) break; } - printf("/%.*s/\en", nread, buf); + printf("/%.*s/\en", (int) nread, buf); } exit(EXIT_SUCCESS); -- 2.28.0 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] fopencookie.3: printf()'s .* expects an int; cast accordingly 2020-09-07 10:21 ` [PATCH 1/2] fopencookie.3: printf()'s .* expects an int; cast accordingly Alejandro Colomar @ 2020-09-07 10:31 ` Michael Kerrisk (man-pages) 0 siblings, 0 replies; 5+ messages in thread From: Michael Kerrisk (man-pages) @ 2020-09-07 10:31 UTC (permalink / raw) To: Alejandro Colomar; +Cc: mtk.manpages, linux-man Hello ALex, On 9/7/20 12:21 PM, Alejandro Colomar wrote: > Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com> > --- > man3/fopencookie.3 | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) Thanks. Patch applied. Cheers, Michael > diff --git a/man3/fopencookie.3 b/man3/fopencookie.3 > index 472a7f3d2..5394ce4a5 100644 > --- a/man3/fopencookie.3 > +++ b/man3/fopencookie.3 > @@ -438,7 +438,7 @@ main(int argc, char *argv[]) > break; > } > > - printf("/%.*s/\en", nread, buf); > + printf("/%.*s/\en", (int) nread, buf); > } > > exit(EXIT_SUCCESS); > -- Michael Kerrisk Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ Linux/UNIX System Programming Training: http://man7.org/training/ ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 2/2] fopencookie.3: Fix bugs in example 2020-09-07 10:21 [PATCH 0/2] fopencookie.3: Fix EXAMPLES section Alejandro Colomar 2020-09-07 10:21 ` [PATCH 1/2] fopencookie.3: printf()'s .* expects an int; cast accordingly Alejandro Colomar @ 2020-09-07 10:21 ` Alejandro Colomar 2020-09-07 10:34 ` Michael Kerrisk (man-pages) 1 sibling, 1 reply; 5+ messages in thread From: Alejandro Colomar @ 2020-09-07 10:21 UTC (permalink / raw) To: mtk.manpages; +Cc: linux-man, Alejandro Colomar fread(3), unlike read(2) which returns a ssize_t, returns a size_t. It doesn't distinguish between error and enf-of-file. Instead, either ferror(3) or feof(3) need to be checked if fread() returned 0. Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com> --- man3/fopencookie.3 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/man3/fopencookie.3 b/man3/fopencookie.3 index 5394ce4a5..055ec64d7 100644 --- a/man3/fopencookie.3 +++ b/man3/fopencookie.3 @@ -392,7 +392,7 @@ main(int argc, char *argv[]) }; FILE *stream; struct memfile_cookie mycookie; - ssize_t nread; + size_t nread; char buf[1000]; /* Set up the cookie before calling fopencookie() */ @@ -429,11 +429,11 @@ main(int argc, char *argv[]) exit(EXIT_FAILURE); } nread = fread(buf, 1, 2, stream); - if (nread == \-1) { - perror("fread"); - exit(EXIT_FAILURE); - } if (nread == 0) { + if (ferror(stream) != 0) { + fprintf(stderr, "fread failed\en"); + exit(EXIT_FAILURE); + } printf("Reached end of file\en"); break; } -- 2.28.0 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] fopencookie.3: Fix bugs in example 2020-09-07 10:21 ` [PATCH 2/2] fopencookie.3: Fix bugs in example Alejandro Colomar @ 2020-09-07 10:34 ` Michael Kerrisk (man-pages) 0 siblings, 0 replies; 5+ messages in thread From: Michael Kerrisk (man-pages) @ 2020-09-07 10:34 UTC (permalink / raw) To: Alejandro Colomar; +Cc: mtk.manpages, linux-man Hello Alex, On 9/7/20 12:21 PM, Alejandro Colomar wrote: > fread(3), unlike read(2) which returns a ssize_t, returns a size_t. > It doesn't distinguish between error and enf-of-file. > Instead, either ferror(3) or feof(3) need to be checked if > fread() returned 0. Well, gosh, the person who wrote that example really should have read the documentation more closely :-}. Thanks. Patch applied. Cheers, Michael > Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com> > --- > man3/fopencookie.3 | 10 +++++----- > 1 file changed, 5 insertions(+), 5 deletions(-) > > diff --git a/man3/fopencookie.3 b/man3/fopencookie.3 > index 5394ce4a5..055ec64d7 100644 > --- a/man3/fopencookie.3 > +++ b/man3/fopencookie.3 > @@ -392,7 +392,7 @@ main(int argc, char *argv[]) > }; > FILE *stream; > struct memfile_cookie mycookie; > - ssize_t nread; > + size_t nread; > char buf[1000]; > > /* Set up the cookie before calling fopencookie() */ > @@ -429,11 +429,11 @@ main(int argc, char *argv[]) > exit(EXIT_FAILURE); > } > nread = fread(buf, 1, 2, stream); > - if (nread == \-1) { > - perror("fread"); > - exit(EXIT_FAILURE); > - } > if (nread == 0) { > + if (ferror(stream) != 0) { > + fprintf(stderr, "fread failed\en"); > + exit(EXIT_FAILURE); > + } > printf("Reached end of file\en"); > break; > } > -- Michael Kerrisk Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ Linux/UNIX System Programming Training: http://man7.org/training/ ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2020-09-07 10:35 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2020-09-07 10:21 [PATCH 0/2] fopencookie.3: Fix EXAMPLES section Alejandro Colomar 2020-09-07 10:21 ` [PATCH 1/2] fopencookie.3: printf()'s .* expects an int; cast accordingly Alejandro Colomar 2020-09-07 10:31 ` Michael Kerrisk (man-pages) 2020-09-07 10:21 ` [PATCH 2/2] fopencookie.3: Fix bugs in example Alejandro Colomar 2020-09-07 10:34 ` Michael Kerrisk (man-pages)
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox