aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2012-10-04 09:34:48 +0200
committerMax Kellermann <max@duempel.org>2012-10-04 10:31:53 +0200
commitefbf184fe80c61f7666ded3342fcb97c1b770758 (patch)
tree82a7e8abd83e7edd68a1983ca16daae6753d625e
parentdd577fb857141bc0d8bfa094a4697163b17deaad (diff)
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().
-rw-r--r--Makefile.am1
-rw-r--r--src/CommandError.cxx7
-rw-r--r--src/PlaylistFile.cxx7
-rw-r--r--src/client_file.c4
-rw-r--r--src/io_error.h44
-rw-r--r--src/tag_id3.c3
6 files changed, 58 insertions, 8 deletions
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 <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 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 <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 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 <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;