logo

utils-std

Collection of commonly available Unix tools
commit: 2573ccd49c3e7ac6aca4b1efabdcc38cd280a419
parent 3214bb70cc59d23d1a86dfdbee6c08585f7cf258
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Wed,  8 Nov 2023 07:02:49 +0100

cmd/base64: Add fflush/ferror checks

Diffstat:

Mcmd/base64.c36+++++++++++++++++++++++++++++++++++-
1 file changed, 35 insertions(+), 1 deletion(-)

diff --git a/cmd/base64.c b/cmd/base64.c @@ -29,6 +29,13 @@ xputc(int c, FILE *stream) return 1; } + int err = ferror(stream); + if(err != 0) + { + fprintf(stderr, "base64: Error writing: %s\n", strerror(err)); + return 1; + } + return 0; } @@ -103,7 +110,22 @@ encode(FILE *fin, const char *name) if(xputc('\n', stdout) != 0) return 1; } - if(feof(fin)) return 0; + if(feof(fin)) + { + if(fflush(stdout)) + { + fprintf(stderr, "base64: Error writing: %s\n", strerror(errno)); + return 1; + } + int err = ferror(stdout); + if(err != 0) + { + fprintf(stderr, "base64: Error writing: %s\n", strerror(err)); + return 1; + } + + return 0; + } } abort(); // unreachable @@ -202,6 +224,18 @@ decode(FILE *fin, const char *name) assert(c == EOF || state == 0); + if(fflush(stdout)) + { + fprintf(stderr, "base64: Error writing: %s\n", strerror(errno)); + return 1; + } + int err = ferror(stdout); + if(err != 0) + { + fprintf(stderr, "base64: Error writing: %s\n", strerror(err)); + return 1; + } + return 0; }