Add printf attributes in exported headers

gcc (and other compilers) sometimes generate spurious warnings, and
thus users of public headers must be able to disable warnings.

Printf format attributes can be disabled by setting
    #define _sd_printf_attr_
before including the header file.

Also, add similar logic for sentinel attribute:
    #define _sd_sentinel_attr_
before including the header file disables the attribute.
parent b1e2b33c
...@@ -32,6 +32,14 @@ ...@@ -32,6 +32,14 @@
extern "C" { extern "C" {
#endif #endif
#ifndef _sd_printf_attr_
# if __GNUC__ >= 4
# define _sd_printf_attr_(a,b) __attribute__ ((format (printf, a, b)))
# else
# define _sd_printf_attr_(a,b)
# endif
#endif
/* TODO: /* TODO:
* - add page donation logic * - add page donation logic
* - api for appending/reading fixed arrays * - api for appending/reading fixed arrays
...@@ -187,7 +195,7 @@ int sd_bus_get_owner_machine_id(sd_bus *bus, const char *name, sd_id128_t *machi ...@@ -187,7 +195,7 @@ int sd_bus_get_owner_machine_id(sd_bus *bus, const char *name, sd_id128_t *machi
#define SD_BUS_ERROR_MAKE(name, message) ((sd_bus_error) {(name), (message), 0}) #define SD_BUS_ERROR_MAKE(name, message) ((sd_bus_error) {(name), (message), 0})
void sd_bus_error_free(sd_bus_error *e); void sd_bus_error_free(sd_bus_error *e);
int sd_bus_error_set(sd_bus_error *e, const char *name, const char *format, ...); int sd_bus_error_set(sd_bus_error *e, const char *name, const char *format, ...) _sd_printf_attr_(3, 0);
void sd_bus_error_set_const(sd_bus_error *e, const char *name, const char *message); void sd_bus_error_set_const(sd_bus_error *e, const char *name, const char *message);
int sd_bus_error_copy(sd_bus_error *dest, const sd_bus_error *e); int sd_bus_error_copy(sd_bus_error *dest, const sd_bus_error *e);
int sd_bus_error_is_set(const sd_bus_error *e); int sd_bus_error_is_set(const sd_bus_error *e);
......
...@@ -68,11 +68,11 @@ extern "C" { ...@@ -68,11 +68,11 @@ extern "C" {
*/ */
#ifndef _sd_printf_attr_ #ifndef _sd_printf_attr_
#if __GNUC__ >= 4 # if __GNUC__ >= 4
#define _sd_printf_attr_(a,b) __attribute__ ((format (printf, a, b))) # define _sd_printf_attr_(a,b) __attribute__ ((format (printf, a, b)))
#else # else
#define _sd_printf_attr_(a,b) # define _sd_printf_attr_(a,b)
#endif # endif
#endif #endif
/* /*
......
...@@ -34,19 +34,31 @@ ...@@ -34,19 +34,31 @@
extern "C" { extern "C" {
#endif #endif
#ifndef _sd_printf_attr_
# if __GNUC__ >= 4
# define _sd_printf_attr_(a,b) __attribute__ ((format (printf, a, b)))
# else
# define _sd_printf_attr_(a,b)
# endif
#endif
#ifndef _sd_sentinel_attr_
# define _sd_sentinel_attr_ __attribute__((sentinel))
#endif
/* Journal APIs. See sd-journal(3) for more information. */ /* Journal APIs. See sd-journal(3) for more information. */
/* Write to daemon */ /* Write to daemon */
int sd_journal_print(int priority, const char *format, ...) __attribute__ ((format (printf, 2, 3))); int sd_journal_print(int priority, const char *format, ...) _sd_printf_attr_(2, 3);
int sd_journal_printv(int priority, const char *format, va_list ap); int sd_journal_printv(int priority, const char *format, va_list ap) _sd_printf_attr_(2, 0);
int sd_journal_send(const char *format, ...) __attribute__((sentinel)); int sd_journal_send(const char *format, ...) _sd_printf_attr_(1, 0) _sd_sentinel_attr_;
int sd_journal_sendv(const struct iovec *iov, int n); int sd_journal_sendv(const struct iovec *iov, int n);
int sd_journal_perror(const char *message); int sd_journal_perror(const char *message);
/* Used by the macros below. Don't call this directly. */ /* Used by the macros below. Don't call this directly. */
int sd_journal_print_with_location(int priority, const char *file, const char *line, const char *func, const char *format, ...) __attribute__ ((format (printf, 5, 6))); int sd_journal_print_with_location(int priority, const char *file, const char *line, const char *func, const char *format, ...) _sd_printf_attr_(5, 6);
int sd_journal_printv_with_location(int priority, const char *file, const char *line, const char *func, const char *format, va_list ap); int sd_journal_printv_with_location(int priority, const char *file, const char *line, const char *func, const char *format, va_list ap) _sd_printf_attr_(5, 0);
int sd_journal_send_with_location(const char *file, const char *line, const char *func, const char *format, ...) __attribute__((sentinel)); int sd_journal_send_with_location(const char *file, const char *line, const char *func, const char *format, ...) _sd_printf_attr_(4, 0) _sd_sentinel_attr_;
int sd_journal_sendv_with_location(const char *file, const char *line, const char *func, const struct iovec *iov, int n); int sd_journal_sendv_with_location(const char *file, const char *line, const char *func, const struct iovec *iov, int n);
int sd_journal_perror_with_location(const char *file, const char *line, const char *func, const char *message); int sd_journal_perror_with_location(const char *file, const char *line, const char *func, const char *message);
......
...@@ -16,13 +16,13 @@ ...@@ -16,13 +16,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef _UDEV_H_ #pragma once
#define _UDEV_H_
#include <sys/types.h> #include <sys/types.h>
#include <sys/param.h> #include <sys/param.h>
#include <signal.h> #include <signal.h>
#include "macro.h"
#include "libudev.h" #include "libudev.h"
#include "libudev-private.h" #include "libudev-private.h"
#include "util.h" #include "util.h"
...@@ -195,7 +195,7 @@ int udev_builtin_hwdb_lookup(struct udev_device *dev, const char *modalias, bool ...@@ -195,7 +195,7 @@ int udev_builtin_hwdb_lookup(struct udev_device *dev, const char *modalias, bool
/* udev logging */ /* udev logging */
void udev_main_log(struct udev *udev, int priority, void udev_main_log(struct udev *udev, int priority,
const char *file, int line, const char *fn, const char *file, int line, const char *fn,
const char *format, va_list args); const char *format, va_list args) _printf_attr_(6, 0);
/* udevadm commands */ /* udevadm commands */
struct udevadm_cmd { struct udevadm_cmd {
...@@ -212,4 +212,3 @@ extern const struct udevadm_cmd udevadm_monitor; ...@@ -212,4 +212,3 @@ extern const struct udevadm_cmd udevadm_monitor;
extern const struct udevadm_cmd udevadm_hwdb; extern const struct udevadm_cmd udevadm_hwdb;
extern const struct udevadm_cmd udevadm_test; extern const struct udevadm_cmd udevadm_test;
extern const struct udevadm_cmd udevadm_test_builtin; extern const struct udevadm_cmd udevadm_test_builtin;
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment