logo

utils-std

Collection of commonly available Unix tools
commit: 5ded09959903e68ef1be525d24b9670df8befcfe
parent 5e5ade7c0ae60211fde92f2ed4aad2e5461b5441
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Thu, 28 Mar 2024 18:53:14 +0100

cmd/strings: assert(errno == 0)

Diffstat:

Mcmd/strings.c7++++++-
1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/cmd/strings.c b/cmd/strings.c @@ -3,6 +3,7 @@ // SPDX-License-Identifier: MPL-2.0 #define _POSIX_C_SOURCE 200809L +#include <assert.h> #include <ctype.h> /* isprint() */ #include <errno.h> /* errno */ #include <fcntl.h> /* open(), O_RDONLY */ @@ -33,6 +34,7 @@ print_string(char *buffer, size_t offset) if(ret < 0) { fprintf(stderr, "strings: Error writing: %s\n", strerror(errno)); + errno = 0; return 1; } else @@ -88,6 +90,7 @@ concat(int fd, const char *fdname) if(c < 0) { fprintf(stderr, "strings: Error reading ā€˜%sā€™: %s\n", fdname, strerror(errno)); + errno = 0; return 1; } @@ -115,7 +118,7 @@ main(int argc, char *argv[]) /* Structure is always ignored */ break; case 'n': - errno = 0; + assert(errno == 0); char *endptr = ""; opt_min_strlen = strtol(optarg, &endptr, 10); if(*endptr != 0) @@ -188,6 +191,7 @@ main(int argc, char *argv[]) } else { + assert(errno == 0); int fd = open(argv[argi], O_RDONLY); if(fd <= 0) { @@ -200,6 +204,7 @@ main(int argc, char *argv[]) return 1; } + assert(errno == 0); if(close(fd) < 0) { fprintf(stderr, "strings: Error closing ā€˜%sā€™: %s\n", argv[argi], strerror(errno));