From 0095c45415ad24338342369d76d5635088294eae Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 7 Nov 2013 16:44:48 +0100 Subject: [PATCH] api: replace manual C++ guards by macros --- src/systemd/_sd-common.h | 28 +++++++++++++++++++++++++--- src/systemd/sd-bus-protocol.h | 10 ++++------ src/systemd/sd-bus-vtable.h | 10 ++++------ src/systemd/sd-bus.h | 8 ++------ src/systemd/sd-event.h | 10 ++++------ src/systemd/sd-id128.h | 10 ++++------ src/systemd/sd-journal.h | 20 ++++++++------------ src/systemd/sd-login.h | 10 ++++------ src/systemd/sd-memfd.h | 10 ++++------ src/systemd/sd-messages.h | 9 +++------ src/systemd/sd-rtnl.h | 10 ++++------ src/systemd/sd-utf8.h | 10 ++++------ 12 files changed, 70 insertions(+), 75 deletions(-) diff --git a/src/systemd/_sd-common.h b/src/systemd/_sd-common.h index b861e3354..b0c48aab9 100644 --- a/src/systemd/_sd-common.h +++ b/src/systemd/_sd-common.h @@ -40,9 +40,31 @@ # define _sd_packed_ __attribute__((packed)) #endif -#ifndef _sd_stringify -# define _sd_xstringify(x) #x -# define _sd_stringify(x) _sd_xstringify(x) +#ifndef _SD_STRINGIFY +# define _SD_XSTRINGIFY(x) #x +# define _SD_STRINGIFY(x) _SD_XSTRINGIFY(x) +#endif + +#ifndef _SD_BEGIN_DECLARATIONS +# ifdef __cplusplus +# define _SD_BEGIN_DECLARATIONS \ + extern "C" { \ + struct __useless_struct_to_allow_trailing_semicolon__ +# else +# define _SD_BEGIN_DECLARATIONS \ + struct __useless_struct_to_allow_trailing_semicolon__ +# endif +#endif + +#ifndef _SD_END_DECLARATIONS +# ifdef __cplusplus +# define _SD_END_DECLARATIONS \ + } \ + struct __useless_struct_to_allow_trailing_semicolon__ +# else +# define _SD_END_DECLARATIONS \ + struct __useless_struct_to_allow_trailing_semicolon__ +# endif #endif #endif diff --git a/src/systemd/sd-bus-protocol.h b/src/systemd/sd-bus-protocol.h index ff2bcc93b..07fade603 100644 --- a/src/systemd/sd-bus-protocol.h +++ b/src/systemd/sd-bus-protocol.h @@ -24,9 +24,9 @@ #include -#ifdef __cplusplus -extern "C" { -#endif +#include "_sd-common.h" + +_SD_BEGIN_DECLARATIONS; /* Types of message */ @@ -213,8 +213,6 @@ enum { #define SD_BUS_ERROR_INVALID_SIGNATURE "org.freedesktop.DBus.Error.InvalidSignature" #define SD_BUS_ERROR_INCONSISTENT_MESSAGE "org.freedesktop.DBus.Error.InconsistentMessage" -#ifdef __cplusplus -} -#endif +_SD_END_DECLARATIONS; #endif diff --git a/src/systemd/sd-bus-vtable.h b/src/systemd/sd-bus-vtable.h index d1642bae5..18fc30bd2 100644 --- a/src/systemd/sd-bus-vtable.h +++ b/src/systemd/sd-bus-vtable.h @@ -22,9 +22,9 @@ along with systemd; If not, see . ***/ -#ifdef __cplusplus -extern "C" { -#endif +#include "_sd-common.h" + +_SD_BEGIN_DECLARATIONS; typedef struct sd_bus_vtable sd_bus_vtable; @@ -128,8 +128,6 @@ struct sd_bus_vtable { .type = _SD_BUS_VTABLE_END, \ } -#ifdef __cplusplus -} -#endif +_SD_END_DECLARATIONS; #endif diff --git a/src/systemd/sd-bus.h b/src/systemd/sd-bus.h index 48edc5918..e6264074e 100644 --- a/src/systemd/sd-bus.h +++ b/src/systemd/sd-bus.h @@ -30,9 +30,7 @@ #include "sd-memfd.h" #include "_sd-common.h" -#ifdef __cplusplus -extern "C" { -#endif +_SD_BEGIN_DECLARATIONS; /* Types */ @@ -269,8 +267,6 @@ int sd_bus_error_has_name(const sd_bus_error *e, const char *name); &(x).bytes[8], &(x).bytes[9], &(x).bytes[10], &(x).bytes[11], \ &(x).bytes[12], &(x).bytes[13], &(x).bytes[14], &(x).bytes[15] -#ifdef __cplusplus -} -#endif +_SD_END_DECLARATIONS; #endif diff --git a/src/systemd/sd-event.h b/src/systemd/sd-event.h index bc4c01db0..8262e139a 100644 --- a/src/systemd/sd-event.h +++ b/src/systemd/sd-event.h @@ -28,6 +28,8 @@ #include #include +#include "_sd-common.h" + /* Why is this better than pure epoll? @@ -37,9 +39,7 @@ - Handles signals and child PIDs */ -#ifdef __cplusplus -extern "C" { -#endif +_SD_BEGIN_DECLARATIONS; typedef struct sd_event sd_event; typedef struct sd_event_source sd_event_source; @@ -115,8 +115,6 @@ int sd_event_source_get_time_accuracy(sd_event_source *s, uint64_t *usec); int sd_event_source_get_signal(sd_event_source *s); int sd_event_source_get_child_pid(sd_event_source *s, pid_t *pid); -#ifdef __cplusplus -} -#endif +_SD_END_DECLARATIONS; #endif diff --git a/src/systemd/sd-id128.h b/src/systemd/sd-id128.h index 6066f395f..5bae9655c 100644 --- a/src/systemd/sd-id128.h +++ b/src/systemd/sd-id128.h @@ -25,9 +25,9 @@ #include #include -#ifdef __cplusplus -extern "C" { -#endif +#include "_sd-common.h" + +_SD_BEGIN_DECLARATIONS; /* 128 Bit ID APIs. See sd-id128(3) for more information. */ @@ -102,8 +102,6 @@ static inline int sd_id128_equal(sd_id128_t a, sd_id128_t b) { #define SD_ID128_NULL ((sd_id128_t) { .qwords = { 0, 0 }}) -#ifdef __cplusplus -} -#endif +_SD_END_DECLARATIONS; #endif diff --git a/src/systemd/sd-journal.h b/src/systemd/sd-journal.h index e319c6e58..751e7f9ea 100644 --- a/src/systemd/sd-journal.h +++ b/src/systemd/sd-journal.h @@ -31,12 +31,10 @@ #include "sd-id128.h" #include "_sd-common.h" -#ifdef __cplusplus -extern "C" { -#endif - /* Journal APIs. See sd-journal(3) for more information. */ +_SD_BEGIN_DECLARATIONS; + /* Write to daemon */ int sd_journal_print(int priority, const char *format, ...) _sd_printf_(2, 3); int sd_journal_printv(int priority, const char *format, va_list ap) _sd_printf_(2, 0); @@ -54,11 +52,11 @@ int sd_journal_perror_with_location(const char *file, const char *line, const ch /* implicitly add code location to messages sent, if this is enabled */ #ifndef SD_JOURNAL_SUPPRESS_LOCATION -#define sd_journal_print(priority, ...) sd_journal_print_with_location(priority, "CODE_FILE=" __FILE__, "CODE_LINE=" _sd_stringify(__LINE__), __func__, __VA_ARGS__) -#define sd_journal_printv(priority, format, ap) sd_journal_printv_with_location(priority, "CODE_FILE=" __FILE__, "CODE_LINE=" _sd_stringify(__LINE__), __func__, format, ap) -#define sd_journal_send(...) sd_journal_send_with_location("CODE_FILE=" __FILE__, "CODE_LINE=" _sd_stringify(__LINE__), __func__, __VA_ARGS__) -#define sd_journal_sendv(iovec, n) sd_journal_sendv_with_location("CODE_FILE=" __FILE__, "CODE_LINE=" _sd_stringify(__LINE__), __func__, iovec, n) -#define sd_journal_perror(message) sd_journal_perror_with_location("CODE_FILE=" __FILE__, "CODE_LINE=" _sd_stringify(__LINE__), __func__, message) +#define sd_journal_print(priority, ...) sd_journal_print_with_location(priority, "CODE_FILE=" __FILE__, "CODE_LINE=" _SD_STRINGIFY(__LINE__), __func__, __VA_ARGS__) +#define sd_journal_printv(priority, format, ap) sd_journal_printv_with_location(priority, "CODE_FILE=" __FILE__, "CODE_LINE=" _SD_STRINGIFY(__LINE__), __func__, format, ap) +#define sd_journal_send(...) sd_journal_send_with_location("CODE_FILE=" __FILE__, "CODE_LINE=" _SD_STRINGIFY(__LINE__), __func__, __VA_ARGS__) +#define sd_journal_sendv(iovec, n) sd_journal_sendv_with_location("CODE_FILE=" __FILE__, "CODE_LINE=" _SD_STRINGIFY(__LINE__), __func__, iovec, n) +#define sd_journal_perror(message) sd_journal_perror_with_location("CODE_FILE=" __FILE__, "CODE_LINE=" _SD_STRINGIFY(__LINE__), __func__, message) #endif @@ -153,8 +151,6 @@ int sd_journal_get_catalog_for_message_id(sd_id128_t id, char **ret); #define SD_JOURNAL_FOREACH_UNIQUE(j, data, l) \ for (sd_journal_restart_unique(j); sd_journal_enumerate_unique((j), &(data), &(l)) > 0; ) -#ifdef __cplusplus -} -#endif +_SD_END_DECLARATIONS; #endif diff --git a/src/systemd/sd-login.h b/src/systemd/sd-login.h index 961bd88ec..a230aff4c 100644 --- a/src/systemd/sd-login.h +++ b/src/systemd/sd-login.h @@ -25,9 +25,7 @@ #include #include -#ifdef __cplusplus -extern "C" { -#endif +#include "_sd-common.h" /* * A few points: @@ -49,6 +47,8 @@ extern "C" { * See sd-login(3) for more information. */ +_SD_BEGIN_DECLARATIONS; + /* Get session from PID. Note that 'shared' processes of a user are * not attached to a session, but only attached to a user. This will * return an error for system processes and 'shared' processes of a @@ -182,8 +182,6 @@ int sd_login_monitor_get_events(sd_login_monitor *m); /* Get timeout for poll(), as usec value relative to CLOCK_MONOTONIC's epoch */ int sd_login_monitor_get_timeout(sd_login_monitor *m, uint64_t *timeout_usec); -#ifdef __cplusplus -} -#endif +_SD_END_DECLARATIONS; #endif diff --git a/src/systemd/sd-memfd.h b/src/systemd/sd-memfd.h index ee140e48d..f4ef8f102 100644 --- a/src/systemd/sd-memfd.h +++ b/src/systemd/sd-memfd.h @@ -26,9 +26,9 @@ #include #include -#ifdef __cplusplus -extern "C" { -#endif +#include "_sd-common.h" + +_SD_BEGIN_DECLARATIONS; typedef struct sd_memfd sd_memfd; @@ -51,8 +51,6 @@ int sd_memfd_get_sealed(sd_memfd *m); int sd_memfd_get_size(sd_memfd *m, uint64_t *sz); int sd_memfd_set_size(sd_memfd *m, uint64_t sz); -#ifdef __cplusplus -} -#endif +_SD_END_DECLARATIONS; #endif diff --git a/src/systemd/sd-messages.h b/src/systemd/sd-messages.h index 775aa23c0..947bd1a9e 100644 --- a/src/systemd/sd-messages.h +++ b/src/systemd/sd-messages.h @@ -23,10 +23,9 @@ ***/ #include "sd-id128.h" +#include "_sd-common.h" -#ifdef __cplusplus -extern "C" { -#endif +_SD_BEGIN_DECLARATIONS; /* Hey! If you add a new message here, you *must* also update the * message catalog with an appropriate explanation */ @@ -84,8 +83,6 @@ extern "C" { #define SD_MESSAGE_BOOTCHART SD_ID128_MAKE(9f,26,aa,56,2c,f4,40,c2,b1,6c,77,3d,04,79,b5,18) -#ifdef __cplusplus -} -#endif +_SD_END_DECLARATIONS; #endif diff --git a/src/systemd/sd-rtnl.h b/src/systemd/sd-rtnl.h index e3ad37c10..223f40307 100644 --- a/src/systemd/sd-rtnl.h +++ b/src/systemd/sd-rtnl.h @@ -24,9 +24,9 @@ #include -#ifdef __cplusplus -extern "C" { -#endif +#include "_sd-common.h" + +_SD_BEGIN_DECLARATIONS; typedef struct sd_rtnl sd_rtnl; typedef struct sd_rtnl_message sd_rtnl_message; @@ -57,8 +57,6 @@ int sd_rtnl_message_get_type(sd_rtnl_message *m, uint16_t *type); int sd_rtnl_message_append(sd_rtnl_message *m, unsigned short type, const void *data); int sd_rtnl_message_read(sd_rtnl_message *m, unsigned short *type, void **data); -#ifdef __cplusplus -} -#endif +_SD_END_DECLARATIONS; #endif diff --git a/src/systemd/sd-utf8.h b/src/systemd/sd-utf8.h index 54ef5fbd8..4a43eb7c2 100644 --- a/src/systemd/sd-utf8.h +++ b/src/systemd/sd-utf8.h @@ -22,15 +22,13 @@ along with systemd; If not, see . ***/ -#ifdef __cplusplus -extern "C" { -#endif +#include "_sd-common.h" + +_SD_BEGIN_DECLARATIONS; const char *sd_utf8_is_valid(const char *s); const char *sd_ascii_is_valid(const char *s); -#ifdef __cplusplus -} -#endif +_SD_END_DECLARATIONS; #endif -- 2.30.2