diff options
Diffstat (limited to 'src/input/FileInputPlugin.cxx')
-rw-r--r-- | src/input/FileInputPlugin.cxx | 29 |
1 files changed, 13 insertions, 16 deletions
diff --git a/src/input/FileInputPlugin.cxx b/src/input/FileInputPlugin.cxx index 6fd743179..7d1fc0a7f 100644 --- a/src/input/FileInputPlugin.cxx +++ b/src/input/FileInputPlugin.cxx @@ -22,9 +22,10 @@ #include "InputInternal.hxx" #include "InputStream.hxx" #include "InputPlugin.hxx" +#include "util/Error.hxx" +#include "util/Domain.hxx" #include "system/fd_util.h" #include "open.h" -#include "io_error.h" #include <sys/stat.h> #include <unistd.h> @@ -35,6 +36,8 @@ #undef G_LOG_DOMAIN #define G_LOG_DOMAIN "input_file" +static constexpr Domain file_domain("file"); + struct FileInputStream { struct input_stream base; @@ -57,7 +60,7 @@ struct FileInputStream { static struct input_stream * input_file_open(const char *filename, Mutex &mutex, Cond &cond, - GError **error_r) + Error &error) { int fd, ret; struct stat st; @@ -68,24 +71,20 @@ input_file_open(const char *filename, fd = open_cloexec(filename, O_RDONLY|O_BINARY, 0); if (fd < 0) { if (errno != ENOENT && errno != ENOTDIR) - g_set_error(error_r, errno_quark(), errno, - "Failed to open \"%s\": %s", - filename, g_strerror(errno)); + error.FormatErrno("Failed to open \"%s\"", + filename); return nullptr; } ret = fstat(fd, &st); if (ret < 0) { - g_set_error(error_r, errno_quark(), errno, - "Failed to stat \"%s\": %s", - filename, g_strerror(errno)); + error.FormatErrno("Failed to stat \"%s\"", filename); close(fd); return nullptr; } if (!S_ISREG(st.st_mode)) { - g_set_error(error_r, errno_quark(), 0, - "Not a regular file: %s", filename); + error.Format(file_domain, "Not a regular file: %s", filename); close(fd); return nullptr; } @@ -101,14 +100,13 @@ input_file_open(const char *filename, static bool input_file_seek(struct input_stream *is, goffset offset, int whence, - GError **error_r) + Error &error) { FileInputStream *fis = (FileInputStream *)is; offset = (goffset)lseek(fis->fd, (off_t)offset, whence); if (offset < 0) { - g_set_error(error_r, errno_quark(), errno, - "Failed to seek: %s", g_strerror(errno)); + error.SetErrno("Failed to seek"); return false; } @@ -118,15 +116,14 @@ input_file_seek(struct input_stream *is, goffset offset, int whence, static size_t input_file_read(struct input_stream *is, void *ptr, size_t size, - GError **error_r) + Error &error) { FileInputStream *fis = (FileInputStream *)is; ssize_t nbytes; nbytes = read(fis->fd, ptr, size); if (nbytes < 0) { - g_set_error(error_r, errno_quark(), errno, - "Failed to read: %s", g_strerror(errno)); + error.SetErrno("Failed to read"); return 0; } |