From efbf184fe80c61f7666ded3342fcb97c1b770758 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 4 Oct 2012 09:34:48 +0200 Subject: PlaylistFile, client_file, tag_id3: don't use g_file_error_quark() g_file_error_quark() is meant to be used with the GFileError enum which does not correspond with errno, but must be converted with g_file_error_from_errno(). At the same time, this removes g_strerror() use for g_file_error_quark(). --- Makefile.am | 1 + src/CommandError.cxx | 7 ++++++- src/PlaylistFile.cxx | 7 +++---- src/client_file.c | 4 ++-- src/io_error.h | 44 ++++++++++++++++++++++++++++++++++++++++++++ src/tag_id3.c | 3 ++- 6 files changed, 58 insertions(+), 8 deletions(-) create mode 100644 src/io_error.h diff --git a/Makefile.am b/Makefile.am index 161d1e71..92ee671e 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 428a615e..32d3cb5e 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 cb86c13a..3223edee 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 2ee43330..5214ff01 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 #include @@ -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 00000000..c8974836 --- /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 + +#include + +/** + * 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 0971829f..5f589d58 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 #include @@ -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; -- cgit v1.2.3