fopencookie.3: Fix EXAMPLES section
cover fopencookie.3: Fix EXAMPLES section
*** 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(-)
Signature · 1 line
2.28.0
PATCH 1/2 fopencookie.3: printf()'s .* expects an int; cast accordingly
--- man3/fopencookie.3 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
man3/fopencookie.3 +1 -1
@@ -438,7 +438,7 @@ main(int argc, char *argv[]) break; } - printf("/%.*s/\en", nread, buf); + printf("/%.*s/\en", (int) nread, buf); } exit(EXIT_SUCCESS);
Signature · 1 line
2.28.0
Re: [PATCH 1/2] fopencookie.3: printf()'s .* expects an int; cast accordingly
Hello ALex,
Quoted 4 lines · Alejandro Colomar
Signed-off-by Alejandro Colomar <[email protected]>--- man3/fopencookie.3 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Thanks. Patch applied.
Cheers,
Michael
Quoted 14 lines
man3/fopencookie.3 +1
-1@@ -438,7 +438,7 @@ main(int argc, char *argv[]) break; } - printf("/%.*s/\en", nread, buf); + printf("/%.*s/\en", (int) nread, buf); } exit(EXIT_SUCCESS);
Signature · 3 lines
Michael Kerrisk Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ Linux/UNIX System Programming Training: http://man7.org/training/
PATCH 2/2 fopencookie.3: Fix bugs in example
In reply to Alejandro Colomarfread(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.
--- man3/fopencookie.3 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
man3/fopencookie.3 +5 -5
@@ -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; }
Signature · 1 line
2.28.0
Re: [PATCH 2/2] fopencookie.3: Fix bugs in example
Hello Alex,
Quoted 4 lines · Alejandro Colomar
fread(3), unlike read(2) which returns a
ssize_t, returns asize_t. It doesn't distinguish between error and enf-of-file. Instead, either ferror(3) or feof(3) need to be checked iffread()returned 0.
Well, gosh, the person who wrote that example really should have read the documentation more closely :-}.
Thanks. Patch applied.
Cheers,
Michael
Quoted 35 lines
Signed-off-by Alejandro Colomar <[email protected]>--- man3/fopencookie.3 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)man3/fopencookie.3 +5
-5@@ -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; }
Signature · 3 lines
Michael Kerrisk Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ Linux/UNIX System Programming Training: http://man7.org/training/