From 860a455471455dade7b156c255ecddbffd2ee6dd Mon Sep 17 00:00:00 2001 From: Takashi Sakamoto Date: Sat, 2 Apr 2022 10:46:22 +0900 Subject: [PATCH] utils: add utility macros to generate GError with file domain It's convenient to add macro to generate GError with file domain since failure of operation over sysfs is reported in the domain. This commit adds such macro. Signed-off-by: Takashi Sakamoto --- src/ctl/card.c | 5 ++--- src/ctl/query.c | 3 --- src/hwdep/query.c | 6 ------ src/rawmidi/query.c | 6 ------ src/rawmidi/stream-pair.c | 5 ++--- src/seq/query.c | 8 +------- src/seq/user-client.c | 5 ++--- src/timer/query.c | 10 ++-------- src/timer/user-instance.c | 5 ++--- src/utils/utils.h | 3 +++ 10 files changed, 14 insertions(+), 42 deletions(-) diff --git a/src/ctl/card.c b/src/ctl/card.c index d42e58d..77157eb 100644 --- a/src/ctl/card.c +++ b/src/ctl/card.c @@ -1,6 +1,8 @@ // SPDX-License-Identifier: LGPL-3.0-or-later #include "privates.h" +#include + #include #include #include @@ -52,9 +54,6 @@ static const char *const err_msgs[] = { g_set_error(exception, ALSACTL_CARD_ERROR, ALSACTL_CARD_ERROR_FAILED, \ fmt" %d(%s)", arg, errno, strerror(errno)) -#define generate_file_error(exception, code, format, arg) \ - g_set_error(exception, G_FILE_ERROR, code, format, arg) - typedef struct { GSource src; ALSACtlCard *self; diff --git a/src/ctl/query.c b/src/ctl/query.c index 1b89f81..402253d 100644 --- a/src/ctl/query.c +++ b/src/ctl/query.c @@ -10,9 +10,6 @@ * descriptor */ -#define generate_file_error(exception, errno, msg) \ - g_set_error_literal(exception, G_FILE_ERROR, g_file_error_from_errno(errno), msg) - /** * alsactl_get_card_id_list: * @entries: (array length=entry_count)(out): The list of numerical ID for sound diff --git a/src/hwdep/query.c b/src/hwdep/query.c index 5793467..0576b8b 100644 --- a/src/hwdep/query.c +++ b/src/hwdep/query.c @@ -12,12 +12,6 @@ * descriptor */ -#define generate_file_error(error, errno, msg) \ - g_set_error_literal(error, G_FILE_ERROR, g_file_error_from_errno(errno), msg) - -#define generate_file_error_fmt(error, errno, fmt, msg) \ - g_set_error(error, G_FILE_ERROR, g_file_error_from_errno(errno), fmt, msg) - /** * alsahwdep_get_device_id_list: * @card_id: The numerical ID of sound card. diff --git a/src/rawmidi/query.c b/src/rawmidi/query.c index 0be13f2..7d93512 100644 --- a/src/rawmidi/query.c +++ b/src/rawmidi/query.c @@ -12,12 +12,6 @@ * descriptor */ -#define generate_file_error(error, errno, msg) \ - g_set_error_literal(error, G_FILE_ERROR, g_file_error_from_errno(errno), msg) - -#define generate_file_error_fmt(error, errno, fmt, msg) \ - g_set_error(error, G_FILE_ERROR, g_file_error_from_errno(errno), fmt, msg) - /** * alsarawmidi_get_device_id_list: * @card_id: The numerical ID of sound card. diff --git a/src/rawmidi/stream-pair.c b/src/rawmidi/stream-pair.c index 744d3ae..919a0d2 100644 --- a/src/rawmidi/stream-pair.c +++ b/src/rawmidi/stream-pair.c @@ -1,6 +1,8 @@ // SPDX-License-Identifier: LGPL-3.0-or-later #include "privates.h" +#include + #include #include #include @@ -56,9 +58,6 @@ static const char *const err_msgs[] = { #define generate_local_error(error, code) \ g_set_error_literal(error, ALSARAWMIDI_STREAM_PAIR_ERROR, code, err_msgs[code]) -#define generate_file_error(exception, code, format, arg) \ - g_set_error(exception, G_FILE_ERROR, code, format, arg) - #define generate_syscall_error(error, errno, format, arg) \ g_set_error(error, ALSARAWMIDI_STREAM_PAIR_ERROR, \ ALSARAWMIDI_STREAM_PAIR_ERROR_FAILED, \ diff --git a/src/seq/query.c b/src/seq/query.c index 8daefba..ed14133 100644 --- a/src/seq/query.c +++ b/src/seq/query.c @@ -16,12 +16,6 @@ * descriptor */ -#define generate_file_error(exception, errno, msg) \ - g_set_error_literal(exception, G_FILE_ERROR, g_file_error_from_errno(errno), msg) - -#define generate_file_error_fmt(exception, errno, fmt, msg) \ - g_set_error(exception, G_FILE_ERROR, g_file_error_from_errno(errno), fmt, msg) - /** * alsaseq_get_seq_sysname: * @sysname: (out): The sysname of ALSA Sequencer. @@ -75,7 +69,7 @@ static int open_fd(GError **error) fd = open(devname, O_RDONLY); if (fd < 0) - generate_file_error_fmt(error, errno, "open(%s)", devname); + generate_file_error(error, errno, "open(%s)", devname); g_free(devname); return fd; diff --git a/src/seq/user-client.c b/src/seq/user-client.c index 1e0cf86..4166510 100644 --- a/src/seq/user-client.c +++ b/src/seq/user-client.c @@ -1,6 +1,8 @@ // SPDX-License-Identifier: LGPL-3.0-or-later #include "privates.h" +#include + #include #include #include @@ -53,9 +55,6 @@ static const char *const err_msgs[] = { g_set_error(exception, ALSASEQ_USER_CLIENT_ERROR, ALSASEQ_USER_CLIENT_ERROR_FAILED, \ fmt" %d(%s)", arg, errno, strerror(errno)) -#define generate_file_error(exception, code, fmt, arg) \ - g_set_error(exception, G_FILE_ERROR, code, fmt, arg) - typedef struct { GSource src; ALSASeqUserClient *self; diff --git a/src/timer/query.c b/src/timer/query.c index 8deba02..eb3e35e 100644 --- a/src/timer/query.c +++ b/src/timer/query.c @@ -22,12 +22,6 @@ #define SYSFS_SND_TIMER_NODE "/sys/module/snd_timer/" -#define generate_file_error(exception, errno, msg) \ - g_set_error_literal(exception, G_FILE_ERROR, g_file_error_from_errno(errno), msg) - -#define generate_file_error_fmt(exception, errno, fmt, msg) \ - g_set_error(exception, G_FILE_ERROR, g_file_error_from_errno(errno), fmt, msg) - /** * alsatimer_get_sysname: * @sysname: (out): The string for sysname of ALSA Timer. @@ -81,7 +75,7 @@ static int open_fd(GError **error) fd = open(devname, O_RDONLY); if (fd < 0) - generate_file_error_fmt(error, errno, "open(%s)", devname); + generate_file_error(error, errno, "open(%s)", devname); g_free(devname); return fd; @@ -253,7 +247,7 @@ static void timer_get_node_param_value(const char *param_name, char *buf, fd = open(literal, O_RDONLY); if (fd < 0) { - generate_file_error_fmt(error, errno, "open(%s)", literal); + generate_file_error(error, errno, "open(%s)", literal); return; } diff --git a/src/timer/user-instance.c b/src/timer/user-instance.c index 8bccd6d..98d7971 100644 --- a/src/timer/user-instance.c +++ b/src/timer/user-instance.c @@ -1,6 +1,8 @@ // SPDX-License-Identifier: LGPL-3.0-or-later #include "privates.h" +#include + #include #include #include @@ -50,9 +52,6 @@ static const char *const err_msgs[] = { g_set_error(exception, ALSATIMER_USER_INSTANCE_ERROR, ALSATIMER_USER_INSTANCE_ERROR_FAILED, \ fmt" %d(%s)", arg, errno, strerror(errno)) -#define generate_file_error(exception, code, format, arg) \ - g_set_error(exception, G_FILE_ERROR, code, format, arg) - typedef struct { GSource src; ALSATimerUserInstance *self; diff --git a/src/utils/utils.h b/src/utils/utils.h index 67ba1cf..2c6bca1 100644 --- a/src/utils/utils.h +++ b/src/utils/utils.h @@ -6,6 +6,9 @@ #include #include +#define generate_file_error(exception, errno, ...) \ + g_set_error(exception, G_FILE_ERROR, g_file_error_from_errno(errno), __VA_ARGS__) + #define CARD_SYSNAME_PREFIX "card" #define CARD_SYSNAME_TEMPLATE CARD_SYSNAME_PREFIX "%u" #define CONTROL_SYSNAME_TEMPLATE "controlC%u" -- 2.47.3