summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-10-05 22:32:56 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-10-05 22:39:45 +0200
commit40b75c24b1586e4d7ad8a9f4c14dc0b3ff99b8cd (patch)
tree94fbe2f64f7f3623ba405963b46419e5be42fab6 /lib
parent1e24f45ab120ea83a6faab2e4e14038547898f64 (diff)
Add a perror like function for libsquashfs error codes
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib')
-rw-r--r--lib/sqfshelper/Makemodule.am2
-rw-r--r--lib/sqfshelper/perror.c71
2 files changed, 72 insertions, 1 deletions
diff --git a/lib/sqfshelper/Makemodule.am b/lib/sqfshelper/Makemodule.am
index 90a25d2..870cc86 100644
--- a/lib/sqfshelper/Makemodule.am
+++ b/lib/sqfshelper/Makemodule.am
@@ -7,6 +7,6 @@ libsqfshelper_a_SOURCES += lib/sqfshelper/data_reader_dump.c
libsqfshelper_a_SOURCES += lib/sqfshelper/compress.c lib/sqfshelper/comp_opt.c
libsqfshelper_a_SOURCES += lib/sqfshelper/data_writer.c include/highlevel.h
libsqfshelper_a_SOURCES += lib/sqfshelper/get_path.c lib/sqfshelper/io_stdin.c
-libsqfshelper_a_SOURCES += lib/sqfshelper/writer.c
+libsqfshelper_a_SOURCES += lib/sqfshelper/writer.c lib/sqfshelper/perror.c
noinst_LIBRARIES += libsqfshelper.a
diff --git a/lib/sqfshelper/perror.c b/lib/sqfshelper/perror.c
new file mode 100644
index 0000000..6f972d8
--- /dev/null
+++ b/lib/sqfshelper/perror.c
@@ -0,0 +1,71 @@
+/* SPDX-License-Identifier: GPL-3.0-or-later */
+/*
+ * print_version.c
+ *
+ * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
+ */
+#include "config.h"
+
+#include "sqfs/error.h"
+
+#include "highlevel.h"
+
+#include <stdio.h>
+
+void sqfs_perror(const char *file, const char *action, int error_code)
+{
+ const char *errstr;
+
+ switch (error_code) {
+ case SQFS_ERROR_ALLOC:
+ errstr = "out of memory";
+ break;
+ case SQFS_ERROR_IO:
+ errstr = "I/O error";
+ break;
+ case SQFS_ERROR_COMPRESSOR:
+ errstr = "internal compressor error";
+ break;
+ case SQFS_ERROR_INTERNAL:
+ errstr = "internal error";
+ break;
+ case SQFS_ERROR_CORRUPTED:
+ errstr = "data corrupted";
+ break;
+ case SQFS_ERROR_UNSUPPORTED:
+ errstr = "unknown or not supported";
+ break;
+ case SQFS_ERROR_OVERFLOW:
+ errstr = "numeric overflow";
+ break;
+ case SQFS_ERROR_OUT_OF_BOUNDS:
+ errstr = "location out of bounds";
+ break;
+ case SFQS_ERROR_SUPER_MAGIC:
+ errstr = "wrong magic value in super block";
+ break;
+ case SFQS_ERROR_SUPER_VERSION:
+ errstr = "wrong squashfs version in super block";
+ break;
+ case SQFS_ERROR_SUPER_BLOCK_SIZE:
+ errstr = "invalid block size specified in super block";
+ break;
+ case SQFS_ERROR_NOT_DIR:
+ errstr = "target is not a directory";
+ break;
+ case SQFS_ERROR_NO_ENTRY:
+ errstr = "no such file or directory";
+ break;
+ case SQFS_ERROR_LINK_LOOP:
+ errstr = "hard link loop detected";
+ break;
+ case SQFS_ERROR_NOT_FILE:
+ errstr = "target is not a file";
+ break;
+ default:
+ errstr = "libsquashfs returned an unknown error code";
+ break;
+ }
+
+ fprintf(stderr, "%s: %s: %s.\n", file, action, errstr);
+}