diff options
Diffstat (limited to 'src/archive')
-rw-r--r-- | src/archive/Bzip2ArchivePlugin.cxx | 34 | ||||
-rw-r--r-- | src/archive/Iso9660ArchivePlugin.cxx | 31 | ||||
-rw-r--r-- | src/archive/ZzipArchivePlugin.cxx | 34 |
3 files changed, 49 insertions, 50 deletions
diff --git a/src/archive/Bzip2ArchivePlugin.cxx b/src/archive/Bzip2ArchivePlugin.cxx index 182b9ccd1..d997158a0 100644 --- a/src/archive/Bzip2ArchivePlugin.cxx +++ b/src/archive/Bzip2ArchivePlugin.cxx @@ -30,6 +30,8 @@ #include "InputStream.hxx" #include "InputPlugin.hxx" #include "util/RefCount.hxx" +#include "util/Error.hxx" +#include "util/Domain.hxx" #include <stdint.h> #include <stddef.h> @@ -85,7 +87,7 @@ public: virtual input_stream *OpenStream(const char *path, Mutex &mutex, Cond &cond, - GError **error_r) override; + Error &error) override; }; struct Bzip2InputStream { @@ -103,12 +105,14 @@ struct Bzip2InputStream { Mutex &mutex, Cond &cond); ~Bzip2InputStream(); - bool Open(GError **error_r); + bool Open(Error &error); void Close(); }; extern const struct input_plugin bz2_inputplugin; +static constexpr Domain bz2_domain("bz2"); + static inline GQuark bz2_quark(void) { @@ -118,7 +122,7 @@ bz2_quark(void) /* single archive handling allocation helpers */ inline bool -Bzip2InputStream::Open(GError **error_r) +Bzip2InputStream::Open(Error &error) { bzstream.bzalloc = nullptr; bzstream.bzfree = nullptr; @@ -129,8 +133,8 @@ Bzip2InputStream::Open(GError **error_r) int ret = BZ2_bzDecompressInit(&bzstream, 0, 0); if (ret != BZ_OK) { - g_set_error(error_r, bz2_quark(), ret, - "BZ2_bzDecompressInit() has failed"); + error.Set(bz2_domain, ret, + "BZ2_bzDecompressInit() has failed"); return false; } @@ -147,11 +151,11 @@ Bzip2InputStream::Close() /* archive open && listing routine */ static ArchiveFile * -bz2_open(const char *pathname, GError **error_r) +bz2_open(const char *pathname, Error &error) { static Mutex mutex; static Cond cond; - input_stream *is = input_stream_open(pathname, mutex, cond, error_r); + input_stream *is = input_stream_open(pathname, mutex, cond, error); if (is == nullptr) return nullptr; @@ -176,10 +180,10 @@ Bzip2InputStream::~Bzip2InputStream() input_stream * Bzip2ArchiveFile::OpenStream(const char *path, Mutex &mutex, Cond &cond, - GError **error_r) + Error &error) { Bzip2InputStream *bis = new Bzip2InputStream(*this, path, mutex, cond); - if (!bis->Open(error_r)) { + if (!bis->Open(error)) { delete bis; return NULL; } @@ -197,7 +201,7 @@ bz2_is_close(struct input_stream *is) } static bool -bz2_fillbuffer(Bzip2InputStream *bis, GError **error_r) +bz2_fillbuffer(Bzip2InputStream *bis, Error &error) { size_t count; bz_stream *bzstream; @@ -209,7 +213,7 @@ bz2_fillbuffer(Bzip2InputStream *bis, GError **error_r) count = input_stream_read(bis->archive->istream, bis->buffer, sizeof(bis->buffer), - error_r); + error); if (count == 0) return false; @@ -220,7 +224,7 @@ bz2_fillbuffer(Bzip2InputStream *bis, GError **error_r) static size_t bz2_is_read(struct input_stream *is, void *ptr, size_t length, - GError **error_r) + Error &error) { Bzip2InputStream *bis = (Bzip2InputStream *)is; bz_stream *bzstream; @@ -235,7 +239,7 @@ bz2_is_read(struct input_stream *is, void *ptr, size_t length, bzstream->avail_out = length; do { - if (!bz2_fillbuffer(bis, error_r)) + if (!bz2_fillbuffer(bis, error)) return 0; bz_result = BZ2_bzDecompress(bzstream); @@ -246,8 +250,8 @@ bz2_is_read(struct input_stream *is, void *ptr, size_t length, } if (bz_result != BZ_OK) { - g_set_error(error_r, bz2_quark(), bz_result, - "BZ2_bzDecompress() has failed"); + error.Set(bz2_domain, bz_result, + "BZ2_bzDecompress() has failed"); return 0; } } while (bzstream->avail_out == length); diff --git a/src/archive/Iso9660ArchivePlugin.cxx b/src/archive/Iso9660ArchivePlugin.cxx index 97fd8bd52..2fee25311 100644 --- a/src/archive/Iso9660ArchivePlugin.cxx +++ b/src/archive/Iso9660ArchivePlugin.cxx @@ -30,6 +30,8 @@ #include "InputStream.hxx" #include "InputPlugin.hxx" #include "util/RefCount.hxx" +#include "util/Error.hxx" +#include "util/Domain.hxx" #include <cdio/cdio.h> #include <cdio/iso9660.h> @@ -69,16 +71,12 @@ public: virtual input_stream *OpenStream(const char *path, Mutex &mutex, Cond &cond, - GError **error_r) override; + Error &error) override; }; extern const struct input_plugin iso9660_input_plugin; -static inline GQuark -iso9660_quark(void) -{ - return g_quark_from_static_string("iso9660"); -} +static constexpr Domain iso9660_domain("iso9660"); /* archive open && listing routine */ @@ -115,13 +113,13 @@ Iso9660ArchiveFile::Visit(const char *psz_path, ArchiveVisitor &visitor) } static ArchiveFile * -iso9660_archive_open(const char *pathname, GError **error_r) +iso9660_archive_open(const char *pathname, Error &error) { /* open archive */ auto iso = iso9660_open(pathname); if (iso == nullptr) { - g_set_error(error_r, iso9660_quark(), 0, - "Failed to open ISO9660 file %s", pathname); + error.Format(iso9660_domain, + "Failed to open ISO9660 file %s", pathname); return NULL; } @@ -166,12 +164,12 @@ struct Iso9660InputStream { input_stream * Iso9660ArchiveFile::OpenStream(const char *pathname, Mutex &mutex, Cond &cond, - GError **error_r) + Error &error) { auto statbuf = iso9660_ifs_stat_translate(iso, pathname); if (statbuf == nullptr) { - g_set_error(error_r, iso9660_quark(), 0, - "not found in the ISO file: %s", pathname); + error.Format(iso9660_domain, + "not found in the ISO file: %s", pathname); return NULL; } @@ -191,7 +189,8 @@ iso9660_input_close(struct input_stream *is) static size_t -iso9660_input_read(struct input_stream *is, void *ptr, size_t size, GError **error_r) +iso9660_input_read(struct input_stream *is, void *ptr, size_t size, + Error &error) { Iso9660InputStream *iis = (Iso9660InputStream *)is; int toread, readed = 0; @@ -215,9 +214,9 @@ iso9660_input_read(struct input_stream *is, void *ptr, size_t size, GError **err iis->statbuf->lsn + cur_block, no_blocks); if (readed != no_blocks * ISO_BLOCKSIZE) { - g_set_error(error_r, iso9660_quark(), 0, - "error reading ISO file at lsn %lu", - (long unsigned int) cur_block); + error.Format(iso9660_domain, + "error reading ISO file at lsn %lu", + (unsigned long)cur_block); return 0; } if (left_bytes < size) { diff --git a/src/archive/ZzipArchivePlugin.cxx b/src/archive/ZzipArchivePlugin.cxx index d0db7aa37..de2c62b5b 100644 --- a/src/archive/ZzipArchivePlugin.cxx +++ b/src/archive/ZzipArchivePlugin.cxx @@ -30,9 +30,11 @@ #include "InputStream.hxx" #include "InputPlugin.hxx" #include "util/RefCount.hxx" +#include "util/Error.hxx" +#include "util/Domain.hxx" #include <zzip/zzip.h> -#include <glib.h> + #include <string.h> class ZzipArchiveFile final : public ArchiveFile { @@ -61,26 +63,22 @@ public: virtual input_stream *OpenStream(const char *path, Mutex &mutex, Cond &cond, - GError **error_r) override; + Error &error) override; }; extern const struct input_plugin zzip_input_plugin; -static inline GQuark -zzip_quark(void) -{ - return g_quark_from_static_string("zzip"); -} +static constexpr Domain zzip_domain("zzip"); /* archive open && listing routine */ static ArchiveFile * -zzip_archive_open(const char *pathname, GError **error_r) +zzip_archive_open(const char *pathname, Error &error) { ZZIP_DIR *dir = zzip_dir_open(pathname, NULL); if (dir == nullptr) { - g_set_error(error_r, zzip_quark(), 0, - "Failed to open ZIP file %s", pathname); + error.Format(zzip_domain, "Failed to open ZIP file %s", + pathname); return NULL; } @@ -133,12 +131,12 @@ struct ZzipInputStream { input_stream * ZzipArchiveFile::OpenStream(const char *pathname, Mutex &mutex, Cond &cond, - GError **error_r) + Error &error) { ZZIP_FILE *_file = zzip_file_open(dir, pathname, 0); if (_file == nullptr) { - g_set_error(error_r, zzip_quark(), 0, - "not found in the ZIP file: %s", pathname); + error.Format(zzip_domain, "not found in the ZIP file: %s", + pathname); return NULL; } @@ -159,15 +157,14 @@ zzip_input_close(struct input_stream *is) static size_t zzip_input_read(struct input_stream *is, void *ptr, size_t size, - GError **error_r) + Error &error) { ZzipInputStream *zis = (ZzipInputStream *)is; int ret; ret = zzip_file_read(zis->file, ptr, size); if (ret < 0) { - g_set_error(error_r, zzip_quark(), ret, - "zzip_file_read() has failed"); + error.Set(zzip_domain, "zzip_file_read() has failed"); return 0; } @@ -186,13 +183,12 @@ zzip_input_eof(struct input_stream *is) static bool zzip_input_seek(struct input_stream *is, - goffset offset, int whence, GError **error_r) + goffset offset, int whence, Error &error) { ZzipInputStream *zis = (ZzipInputStream *)is; zzip_off_t ofs = zzip_seek(zis->file, offset, whence); if (ofs != -1) { - g_set_error(error_r, zzip_quark(), ofs, - "zzip_seek() has failed"); + error.Set(zzip_domain, "zzip_seek() has failed"); is->offset = ofs; return true; } |