From: Sergey Matveev Date: Wed, 9 Oct 2024 18:02:09 +0000 (+0300) Subject: Replace assert with proper error printing X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=3494eaed74fe1b882993cde008f30e3e754ff6b9ecc371e9d9c95199514f4dbe;p=keks.git Replace assert with proper error printing --- diff --git a/cyac/cmd/print.c b/cyac/cmd/print.c index dc89c2d..7248dd7 100644 --- a/cyac/cmd/print.c +++ b/cyac/cmd/print.c @@ -14,6 +14,7 @@ // License along with this program. If not, see . #include +#include #include #include #include @@ -220,10 +221,16 @@ main(int argc, char **argv) unsigned char *buf = NULL; { int fd = open(argv[1], O_RDONLY | O_CLOEXEC); - assert(fd != -1); + if (fd == -1) { + fprintf(stderr, "%s\n", strerror(errno)); + return EXIT_FAILURE; + } struct stat sb; memset(&sb, 0, sizeof(struct stat)); - assert(fstat(fd, &sb) == 0); + if (fstat(fd, &sb) != 0) { + fprintf(stderr, "%s\n", strerror(errno)); + return EXIT_FAILURE; + } len = (size_t)sb.st_size; buf = mmap(NULL, len, PROT_READ, MAP_SHARED, fd, 0); }