From 66712ffedab80f122f463d98acbbb7745b5dc1ac Mon Sep 17 00:00:00 2001
From: Kubat <mael.martin31@gmail.com>
Date: Thu, 30 Apr 2020 09:56:26 +0200
Subject: [PATCH] Macro for unused arguments

---
 inc/common/common.h         |  3 +++
 meson.build                 |  2 +-
 src/commands.c              | 38 +++++++++++++++++--------------------
 src/common.c                |  6 +++++-
 src/config.c                |  2 +-
 src/main/lkt.c              |  6 ++----
 src/main/lktadm.c           |  8 ++++----
 src/module/module_sdl2.c    | 10 ++++------
 src/module/module_x11.c     |  6 ++++--
 src/mthread/mthread_cond.c  |  2 ++
 src/mthread/mthread_debug.c |  2 ++
 src/mthread/mthread_key.c   |  2 ++
 src/mthread/mthread_mutex.c |  7 ++++---
 src/mthread/mthread_once.c  |  3 +++
 src/mthread/mthread_sem.c   |  2 ++
 src/mthread/mthread_tst.c   |  2 ++
 src/repo/sync.c             |  5 ++---
 17 files changed, 60 insertions(+), 46 deletions(-)

diff --git a/inc/common/common.h b/inc/common/common.h
index 09d87d2d..3dc3bdda 100644
--- a/inc/common/common.h
+++ b/inc/common/common.h
@@ -5,3 +5,6 @@
 
 #define not_implemented() __not_implemented(__func__,__FILE__,__LINE__)
 extern void __not_implemented(const char *func, char *file, int line);
+
+#define UNUSED(...) __unused((void *) __VA_ARGS__)
+void __unused(void *, ...);
diff --git a/meson.build b/meson.build
index fe4628f5..f92d8edd 100644
--- a/meson.build
+++ b/meson.build
@@ -112,7 +112,7 @@ metadata = executable( 'lktadm'
 
 # Client executable
 lkt = executable( 'lkt'
-                , files('src/main/lkt.c', 'src/cmd.c')
+                , files('src/main/lkt.c', 'src/cmd.c', 'src/common.c')
                 , include_directories : includes
                 , install : true
                 )
diff --git a/src/commands.c b/src/commands.c
index dc44865a..57f40c85 100644
--- a/src/commands.c
+++ b/src/commands.c
@@ -1,5 +1,6 @@
 #define _POSIX_C_SOURCE 200809L
 
+#include <common/common.h>
 #include <lektor/macro.h>
 #include <lektor/commands.h>
 #include <lektor/database.h>
@@ -54,7 +55,7 @@ command_restart(struct lkt_state *srv, size_t c)
 bool
 command_update(struct lkt_state *srv, size_t c, char *argv[LKT_MESSAGE_ARGS_MAX])
 {
-    (void) argv;
+    UNUSED(argv);
     RETURN_UNLESS(lkt_client_auth(srv, c, false), "Failed to authentificate user", false);
     srv->mpd_idle_events |= MPD_IDLE_UPDATE;
     srv->mpd_idle_events |= MPD_IDLE_DATABASE;
@@ -64,7 +65,7 @@ command_update(struct lkt_state *srv, size_t c, char *argv[LKT_MESSAGE_ARGS_MAX]
 bool
 command_rescan(struct lkt_state *srv, size_t c, char *argv[LKT_MESSAGE_ARGS_MAX])
 {
-    (void) argv;
+    UNUSED(argv);
     RETURN_UNLESS(lkt_client_auth(srv, c, false), "Failed to authentificate user", false);
     fprintf(stderr, " ! command_rescan: Not implemented\n");
     return false;
@@ -250,7 +251,7 @@ command_add(sqlite3 *db, struct lkt_win *win, char *args[LKT_MESSAGE_ARGS_MAX],
     struct lkt_uri uri;
     char *query = args[0];
     int ret, priority = 1;  /* To be modified according to the command (insert or add) later (TODO) */
-    (void) win;         // No callbacks to the window for the moment
+    UNUSED(win);            /* No callbacks to the window for the moment */
     RETURN_UNLESS(lkt_uri_from(&uri, query), "Failed to parse query", false);
 
     switch (uri.type) {
@@ -289,7 +290,7 @@ bool
 command_addid(sqlite3 *db, struct lkt_win *win, char *args[LKT_MESSAGE_ARGS_MAX],
               enum mpd_idle_flag *watch_mask_ptr)
 {
-    (void) win;
+    UNUSED(win);
     long id;
     char *endptr, *id_str;
     int priority = 1;
@@ -322,7 +323,7 @@ command_crop(sqlite3 *db, enum mpd_idle_flag *watch_mask_ptr)
 bool
 command_delid(sqlite3 *db, struct lkt_win *win, char *id_str, enum mpd_idle_flag *watch_mask_ptr)
 {
-    (void) win;
+    UNUSED(win);
     long id;
     char *endptr;
     int uri = 0;
@@ -438,7 +439,7 @@ command_noidle(struct lkt_state *srv, size_t c)
 static bool
 lkt_callback_print_row_v1(struct lkt_state *srv, size_t c, int id, int id_len, const char *sql_row)
 {
-    (void) srv;
+    UNUSED(srv);
     printf(" . from client %ld:\t%*d:%s\n", c, id_len, id, sql_row);
     return true;
 }
@@ -466,9 +467,7 @@ lkt_callback_send_row_v2(struct lkt_state *srv, size_t c, int id, int id_len, co
 static bool
 lkt_callback_insert_v1(struct lkt_state *srv, size_t c, int id, int id_len, const char *sql_row)
 {
-    (void) c;
-    (void) sql_row;
-    (void) id_len;
+    UNUSED(sql_row, id_len, c);
     return database_queue_add_id((sqlite3 *) srv->db, id, 5);
 }
 
@@ -575,8 +574,7 @@ command_set_playback_option(struct lkt_state *srv, size_t c, enum lkt_playback_o
                             char *args[LKT_MESSAGE_MAX])
 {
     RETURN_UNLESS(srv, "Invalid argument", false);
-
-    (void) c;
+    UNUSED(c);
     long val, ret = false;
     char *endptr;
     struct lkt_win *win = &srv->win;
@@ -846,9 +844,7 @@ command_user_add(struct lkt_state *srv, size_t c, sqlite3 *db, char *argv[LKT_ME
 static bool
 sticker_send_one_value(void *_args, const char *sticker, const char *type, int uri, int value)
 {
-    (void) sticker;
-    (void) type;
-    (void) uri;
+    UNUSED(sticker, type, uri);
     struct sticker_callback *args = (struct sticker_callback *) _args;
     struct lkt_message *out = lkt_message_new();
     out->data_len = snprintf(out->data, LKT_MESSAGE_MAX, "value: %d\n", value);
@@ -871,7 +867,7 @@ static bool
 sticker_send_check_uri(void *_args, const char *sticker, const char *type, int uri, int value)
 {
     struct sticker_callback *args = (struct sticker_callback *) _args;
-    (void) type;
+    UNUSED(type);
 
     if (uri == args->uri) {
         struct lkt_message *out = lkt_message_new();
@@ -887,7 +883,7 @@ sticker_send_value_check_uri_name(void *_args, const char *sticker, const char *
 {
     struct sticker_callback *args = (struct sticker_callback *) _args;
     struct lkt_message *out;
-    (void) type;
+    UNUSED(type);
 
     if (uri == args->uri || !strcasecmp(sticker, args->name)) {
         out = lkt_message_new();
@@ -901,7 +897,7 @@ sticker_send_value_check_uri_name(void *_args, const char *sticker, const char *
 static bool
 sticker_check_is_present_eq(void *_args, const char *sticker, const char *type, int uri, int value)
 {
-    (void) type;
+    UNUSED(type);
     struct sticker_callback *args = (struct sticker_callback *) _args;
     args->is_ok |= (uri == args->uri) && !strcasecmp(sticker, args->name) && (value == args->value);
     return true;
@@ -910,7 +906,7 @@ sticker_check_is_present_eq(void *_args, const char *sticker, const char *type,
 static bool
 sticker_check_is_present_lt(void *_args, const char *sticker, const char *type, int uri, int value)
 {
-    (void) type;
+    UNUSED(type);
     struct sticker_callback *args = (struct sticker_callback *) _args;
     args->is_ok |= (uri == args->uri) && !strcasecmp(sticker, args->name) && (value < args->value);
     return true;
@@ -919,7 +915,7 @@ sticker_check_is_present_lt(void *_args, const char *sticker, const char *type,
 static bool
 sticker_check_is_present_gt(void *_args, const char *sticker, const char *type, int uri, int value)
 {
-    (void) type;
+    UNUSED(type);
     struct sticker_callback *args = (struct sticker_callback *) _args;
     args->is_ok |= (uri == args->uri) && !strcasecmp(sticker, args->name) && (value > args->value);
     return true;
@@ -942,7 +938,7 @@ command_sticker_get(struct lkt_state *srv, size_t c, char *argv[LKT_MESSAGE_ARGS
 bool
 command_sticker_set(struct lkt_state *srv, size_t c, char *argv[LKT_MESSAGE_ARGS_MAX])
 {
-    (void) c;
+    UNUSED(c);
     RETURN_UNLESS(argv[0] && argv[1] && argv[2] && argv[3] && !argv[4], "Invalid argument", false);
     int uri = atoi(argv[1]);    /* FIXME: Use strtol. */
     int value = atoi(argv[4]);  /* FIXME: Use strtol. */
@@ -1023,7 +1019,7 @@ unknown:
 bool
 command_sticker_delete(struct lkt_state *srv, size_t c, char *argv[LKT_MESSAGE_ARGS_MAX])
 {
-    (void) c;
+    UNUSED(c);
     RETURN_UNLESS(argv[0] && argv[1], "Invalid argument", false);
     int uri = atoi(argv[1]);
     srv->mpd_idle_events |= MPD_IDLE_STICKER;
diff --git a/src/common.c b/src/common.c
index f0195a6c..50186eff 100644
--- a/src/common.c
+++ b/src/common.c
@@ -9,4 +9,8 @@ __not_implemented(const char *func, char *file, int line)
     abort();
 }
 
-
+inline void
+__unused(void *dummy, ...)
+{
+    (void) dummy;
+}
diff --git a/src/config.c b/src/config.c
index 29b85b49..7f1b3ada 100644
--- a/src/config.c
+++ b/src/config.c
@@ -90,7 +90,7 @@ static int
 #if INI_HANDLER_LINENO
 handler(void *user, const char *section, const char *name, const char *value, int lineno)
 {
-    (void) lineno;
+    UNUSED(lineno);
 #else
 handler(void *user, const char *section, const char *name, const char *value)
 {
diff --git a/src/main/lkt.c b/src/main/lkt.c
index e74a7c66..fb2b8c25 100644
--- a/src/main/lkt.c
+++ b/src/main/lkt.c
@@ -918,7 +918,7 @@ search_add__(struct lkt_cmd_args *args)
 noreturn void
 search_insert__(struct lkt_cmd_args *args)
 {
-    (void) args;
+    UNUSED(args);
     fail("Not implemented");
 }
 
@@ -1018,9 +1018,7 @@ static struct lkt_cmd_opt options_[] = {
 static void
 sigpipe__(int sig)
 {
-    (void) sig;
-    static const char *errmsg = "Exit because sigpipe\n";
-    write(2, errmsg, strlen(errmsg));
+    LOG_ERROR_SCT("GENERAL", "Exit because of signal sigpipe (%d)", sig);
     exit(EXIT_FAILURE);
 }
 
diff --git a/src/main/lktadm.c b/src/main/lktadm.c
index 5676ad2e..57ee9a57 100644
--- a/src/main/lktadm.c
+++ b/src/main/lktadm.c
@@ -89,7 +89,7 @@ help(void)
 noreturn void
 conf__(struct lkt_cmd_args *args)
 {
-    (void) args;
+    UNUSED(args);
     fprintf(stdout, "%s\n", lkt_default_config_file);
     LOG_INFO("%s", "You may redirect this output to ~/.config/lektor/lektor.ini");
     exit(EXIT_SUCCESS);
@@ -119,7 +119,7 @@ cat__(struct lkt_cmd_args *args)
 noreturn void
 init_metadata__(struct lkt_cmd_args *args)
 {
-    (void) args;
+    UNUSED(args);
     open_db();
     metadata_set_directory(kara_dir, mkvpropedit);
     exit(EXIT_SUCCESS);
@@ -128,7 +128,7 @@ init_metadata__(struct lkt_cmd_args *args)
 noreturn void
 init_populate__(struct lkt_cmd_args *args)
 {
-    (void) args;
+    UNUSED(args);
     open_db();
     database_update(db, kara_dir);
     sqlite3_close(db);
@@ -216,7 +216,7 @@ get__(struct lkt_cmd_args *args)
 noreturn void
 init_database__(struct lkt_cmd_args *args)
 {
-    (void) args;
+    UNUSED(args);
     pid_t pid;
     int wstatus, status, fd;
     open_db();
diff --git a/src/module/module_sdl2.c b/src/module/module_sdl2.c
index efa57e9e..659b5ab7 100644
--- a/src/module/module_sdl2.c
+++ b/src/module/module_sdl2.c
@@ -47,14 +47,14 @@ struct module_sdl2_window {
 static inline void *
 get_proc_address_mpv(void *fn_ctx, const char *name)
 {
-    (void) fn_ctx;
+    UNUSED(fn_ctx);
     return SDL_GL_GetProcAddress(name);
 }
 
 static inline void
 on_mpv_events(void *ctx)
 {
-    (void) ctx;
+    UNUSED(ctx);
     SDL_Event event = { .type = wakeup_on_mpv_events };
     SDL_PushEvent(&event);
 }
@@ -62,7 +62,7 @@ on_mpv_events(void *ctx)
 static inline void
 on_mpv_render_update(void *ctx)
 {
-    (void) ctx;
+    UNUSED(ctx);
     SDL_Event event = { .type = wakeup_on_mpv_render_update };
     SDL_PushEvent(&event);
 }
@@ -348,8 +348,6 @@ module_sdl2_attach(struct lkt_win *const win, void *server)
 bool
 module_sdl2_handle_events(struct lkt_win *const win, sqlite3 *db, enum mpd_idle_flag *mpd_idle_events)
 {
-    (void) win;
-    (void) db;
-    (void) mpd_idle_events;
+    UNUSED(win, db, mpd_idle_events);
     return true;
 }
diff --git a/src/module/module_x11.c b/src/module/module_x11.c
index ef28744b..4ecd9454 100644
--- a/src/module/module_x11.c
+++ b/src/module/module_x11.c
@@ -1,3 +1,6 @@
+#define _POSIX_C_SOURCE 200809L
+
+#include <common/common.h>
 #include <lektor/module/module_x11.h>
 #include <lektor/macro.h>
 #include <lektor/module/mpv.h>
@@ -215,8 +218,7 @@ module_x11_free(struct lkt_win *const win)
 void
 module_x11_attach(struct lkt_win *const win, void *server)
 {
-    (void) win;
-    (void) server;
+    UNUSED(win, server);
 }
 
 bool
diff --git a/src/mthread/mthread_cond.c b/src/mthread/mthread_cond.c
index 00ebe309..ba25bae0 100644
--- a/src/mthread/mthread_cond.c
+++ b/src/mthread/mthread_cond.c
@@ -1,3 +1,5 @@
+#define _POSIX_C_SOURCE 200809L
+
 #include <mthread/mthread_internal.h>
 #include <stdio.h>
 #include <stdlib.h>
diff --git a/src/mthread/mthread_debug.c b/src/mthread/mthread_debug.c
index 8adcdc70..3230f816 100644
--- a/src/mthread/mthread_debug.c
+++ b/src/mthread/mthread_debug.c
@@ -1,3 +1,5 @@
+#define _POSIX_C_SOURCE 200809L
+
 #include <mthread/mthread_internal.h>
 #include <assert.h>
 
diff --git a/src/mthread/mthread_key.c b/src/mthread/mthread_key.c
index fc9741bc..bfd5403c 100644
--- a/src/mthread/mthread_key.c
+++ b/src/mthread/mthread_key.c
@@ -1,3 +1,5 @@
+#define _POSIX_C_SOURCE 200809L
+
 #include <mthread/mthread_internal.h>
 #include <errno.h>
 #include <stdlib.h>
diff --git a/src/mthread/mthread_mutex.c b/src/mthread/mthread_mutex.c
index b82ec5f1..b9ee9843 100644
--- a/src/mthread/mthread_mutex.c
+++ b/src/mthread/mthread_mutex.c
@@ -1,3 +1,6 @@
+#define _POSIX_C_SOURCE 200809L
+
+#include <common/common.h>
 #include <errno.h>
 #include <string.h>
 #include <mthread/mthread_internal.h>
@@ -9,14 +12,12 @@
 int
 mthread_mutex_init(mthread_mutex_t *__mutex, const mthread_mutexattr_t *__mutex_attr)
 {
-    (void) __mutex_attr;
-
+    UNUSED(__mutex_attr);
     __mutex->list        = safe_malloc(sizeof(mthread_list_t));
     __mutex->list->first = NULL;
     __mutex->list->last  = NULL;
     __mutex->nb_thread   = 0;
     __mutex->lock        = 0;
-
     LOG_INFO("%s", "MUTEX initialized");
     return 0;
 }
diff --git a/src/mthread/mthread_once.c b/src/mthread/mthread_once.c
index acab4bcf..9a269a39 100644
--- a/src/mthread/mthread_once.c
+++ b/src/mthread/mthread_once.c
@@ -1,5 +1,8 @@
+#define _POSIX_C_SOURCE 200809L
+
 #include <mthread/mthread_internal.h>
 #include <errno.h>
+
 /* Functions for handling initialization.  */
 
 /* Guarantee that the initialization function INIT_ROUTINE will be called
diff --git a/src/mthread/mthread_sem.c b/src/mthread/mthread_sem.c
index 9c5534ae..6d5acbcf 100644
--- a/src/mthread/mthread_sem.c
+++ b/src/mthread/mthread_sem.c
@@ -1,3 +1,5 @@
+#define _POSIX_C_SOURCE 200809L
+
 #include <mthread/mthread_internal.h>
 
 /* Functions for handling semaphore.  */
diff --git a/src/mthread/mthread_tst.c b/src/mthread/mthread_tst.c
index 35bae165..422eb485 100644
--- a/src/mthread/mthread_tst.c
+++ b/src/mthread/mthread_tst.c
@@ -1,3 +1,5 @@
+#define _POSIX_C_SOURCE 200809L
+
 #include <mthread/mthread_internal.h>
 #include <sched.h>
 
diff --git a/src/repo/sync.c b/src/repo/sync.c
index ce702296..028cca72 100644
--- a/src/repo/sync.c
+++ b/src/repo/sync.c
@@ -1,12 +1,11 @@
 #define _POSIX_C_SOURCE 200809L
 
+#include <common/common.h>
 #include <lektor/repo.h>
 
 int
 repo_sync(struct lkt_repo *const repo, struct lkt_uri *uri, int rescan)
 {
-    (void) repo;
-    (void) rescan;
-    (void) uri;
+    UNUSED(repo, rescan, uri);
     return 1;
 }
-- 
GitLab