logo

utils-std

Collection of commonly available Unix tools
commit: 36538f23a98779c9abb2c807f26796be3ce67f5b
parent 21c374ab77399a99e0e8b5fe1b6f67fdb25cb180
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Thu, 28 Mar 2024 18:27:21 +0100

cmd/base64: assert(errno == 0)

Diffstat:

Mcmd/base64.c14++++++++++++++
1 file changed, 14 insertions(+), 0 deletions(-)

diff --git a/cmd/base64.c b/cmd/base64.c @@ -23,16 +23,20 @@ static long wrap_nl = 76; static int xputc(int c, FILE *stream) { + assert(errno == 0); if(fputc(c, stream) == EOF) { fprintf(stderr, "base64: Error writing: %s\n", strerror(errno)); + errno = 0; return 1; } + assert(errno == 0); int err = ferror(stream); if(err != 0) { fprintf(stderr, "base64: Error writing: %s\n", strerror(err)); + errno = 0; return 1; } @@ -78,9 +82,11 @@ encode(FILE *fin, const char *name) { return 0; }; + assert(errno == 0); if(ferror(fin)) { fprintf(stderr, "base64: Error reading ā€˜%sā€™: %s\n", name, strerror(errno)); + errno = 0; return 1; } for(; c < 3; pad++, c++) @@ -97,9 +103,11 @@ encode(FILE *fin, const char *name) obuf[4 - pad] = '='; } + assert(errno == 0); if(fwrite((char *)obuf, 4, 1, stdout) != 1) { fprintf(stderr, "base64: Error writing: %s\n", strerror(errno)); + errno = 0; return 1; } c_out += 4; @@ -112,9 +120,11 @@ encode(FILE *fin, const char *name) if(feof(fin)) { + assert(errno == 0); if(fflush(stdout)) { fprintf(stderr, "base64: Error writing: %s\n", strerror(errno)); + errno = 0; return 1; } int err = ferror(stdout); @@ -224,15 +234,19 @@ decode(FILE *fin, const char *name) assert(c == EOF || state == 0); + assert(errno == 0); if(fflush(stdout)) { fprintf(stderr, "base64: Error writing: %s\n", strerror(errno)); + errno = 0; return 1; } + assert(errno == 0); int err = ferror(stdout); if(err != 0) { fprintf(stderr, "base64: Error writing: %s\n", strerror(err)); + errno = 0; return 1; }