diff options
-rw-r--r-- | Makefile.am | 1 | ||||
-rw-r--r-- | src/CommandError.cxx | 7 | ||||
-rw-r--r-- | src/PlaylistFile.cxx | 7 | ||||
-rw-r--r-- | src/client_file.c | 4 | ||||
-rw-r--r-- | src/io_error.h | 44 | ||||
-rw-r--r-- | src/tag_id3.c | 3 |
6 files changed, 58 insertions, 8 deletions
diff --git a/Makefile.am b/Makefile.am index 161d1e719..92ee671e4 100644 --- a/Makefile.am +++ b/Makefile.am @@ -295,6 +295,7 @@ src_mpd_SOURCES = \ src/listen.c \ src/log.c \ src/ls.c \ + src/io_error.h \ src/io_thread.c src/io_thread.h \ src/Main.cxx src/Main.hxx \ src/Win32Main.cxx \ diff --git a/src/CommandError.cxx b/src/CommandError.cxx index 428a615e5..32d3cb5ec 100644 --- a/src/CommandError.cxx +++ b/src/CommandError.cxx @@ -20,6 +20,7 @@ #include "config.h" #include "CommandError.hxx" #include "db_error.h" +#include "io_error.h" extern "C" { #include "protocol/result.h" @@ -119,11 +120,15 @@ print_error(struct client *client, GError *error) command_error(client, ACK_ERROR_NO_EXIST, "Not found"); return COMMAND_RETURN_ERROR; } - } else if (error->domain == g_file_error_quark()) { + } else if (error->domain == errno_quark()) { command_error(client, ACK_ERROR_SYSTEM, "%s", g_strerror(error->code)); g_error_free(error); return COMMAND_RETURN_ERROR; + } else if (error->domain == g_file_error_quark()) { + command_error(client, ACK_ERROR_SYSTEM, "%s", error->message); + g_error_free(error); + return COMMAND_RETURN_ERROR; } g_error_free(error); diff --git a/src/PlaylistFile.cxx b/src/PlaylistFile.cxx index cb86c13ac..3223edee3 100644 --- a/src/PlaylistFile.cxx +++ b/src/PlaylistFile.cxx @@ -21,6 +21,7 @@ #include "PlaylistFile.hxx" #include "PlaylistSave.hxx" #include "song.h" +#include "io_error.h" extern "C" { #include "text_file.h" @@ -132,8 +133,7 @@ playlist_errno(GError **error_r) break; default: - g_set_error_literal(error_r, g_file_error_quark(), errno, - g_strerror(errno)); + set_error_errno(error_r); break; } } @@ -181,8 +181,7 @@ ListPlaylistFiles(GError **error_r) DIR *dir = opendir(parent_path_fs); if (dir == NULL) { - g_set_error_literal(error_r, g_file_error_quark(), errno, - g_strerror(errno)); + set_error_errno(error_r); return list; } diff --git a/src/client_file.c b/src/client_file.c index 2ee433308..5214ff019 100644 --- a/src/client_file.c +++ b/src/client_file.c @@ -20,6 +20,7 @@ #include "client_file.h" #include "client.h" #include "ack.h" +#include "io_error.h" #include <sys/stat.h> #include <sys/types.h> @@ -53,8 +54,7 @@ client_allow_file(const struct client *client, const char *path_fs, struct stat st; if (stat(path_fs, &st) < 0) { - g_set_error(error_r, g_file_error_quark(), errno, - "%s", g_strerror(errno)); + set_error_errno(error_r); return false; } diff --git a/src/io_error.h b/src/io_error.h new file mode 100644 index 000000000..c89748360 --- /dev/null +++ b/src/io_error.h @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2003-2012 The Music Player Daemon Project + * http://www.musicpd.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef MPD_IO_ERROR_H +#define MPD_IO_ERROR_H + +#include <glib.h> + +#include <errno.h> + +/** + * A GQuark for GError for I/O errors. The code is an errno value. + */ +G_GNUC_CONST +static inline GQuark +errno_quark(void) +{ + return g_quark_from_static_string("errno"); +} + +static inline void +set_error_errno(GError **error_r) +{ + g_set_error_literal(error_r, errno_quark(), errno, + g_strerror(errno)); +} + +#endif diff --git a/src/tag_id3.c b/src/tag_id3.c index 0971829f0..5f589d58d 100644 --- a/src/tag_id3.c +++ b/src/tag_id3.c @@ -25,6 +25,7 @@ #include "riff.h" #include "aiff.h" #include "conf.h" +#include "io_error.h" #include <glib.h> #include <id3tag.h> @@ -546,7 +547,7 @@ tag_id3_load(const char *path_fs, GError **error_r) { FILE *file = fopen(path_fs, "rb"); if (file == NULL) { - g_set_error(error_r, g_file_error_quark(), errno, + g_set_error(error_r, errno_quark(), errno, "Failed to open file %s: %s", path_fs, g_strerror(errno)); return NULL; |