]> Cypherpunks repositories - keks.git/commitdiff
Replace assert with proper error printing
authorSergey Matveev <stargrave@stargrave.org>
Wed, 9 Oct 2024 18:02:09 +0000 (21:02 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Wed, 9 Oct 2024 18:03:16 +0000 (21:03 +0300)
cyac/cmd/print.c

index dc89c2d4aff1184bf86d903f39630168f136acf21d7737f6df4eb88331c44add..7248dd7cd3fe911c5f3429e4c02c60c2a1f221bc9e0d7025b07304d47a144e6b 100644 (file)
@@ -14,6 +14,7 @@
 // License along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 #include <assert.h>
+#include <errno.h>
 #include <fcntl.h>
 #include <stddef.h>
 #include <stdio.h>
@@ -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);
     }