From b6d82ecee6e38b83776d3a9d4637c51fc5151beb Mon Sep 17 00:00:00 2001 From: David Härdeman Date: Wed, 1 Jul 2015 16:59:01 +0200 Subject: Add support for actually reading keymaps --- utils.h | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'utils.h') diff --git a/utils.h b/utils.h index 33cff05..9cb775b 100644 --- a/utils.h +++ b/utils.h @@ -1,6 +1,8 @@ #ifndef fooutilshfoo #define fooutilshfoo +#include +#include #include struct list_head { @@ -80,6 +82,17 @@ static inline void sd_bus_close_unrefp(sd_bus **bus) { } #define _cleanup_bus_close_unref_ _cleanup_(sd_bus_close_unrefp) +static inline unsigned +strv_length(char **strv) +{ + unsigned len; + + for (len = 0; strv && *strv; strv++) + len++; + + return len; +} + static inline void strv_free(char **l) { char **k; if (l) { @@ -91,9 +104,20 @@ static inline void strv_free(char **l) { DEFINE_TRIVIAL_CLEANUP_FUNC(char **, strv_free); #define _cleanup_strv_free_ _cleanup_(strv_freep) -DEFINE_TRIVIAL_CLEANUP_FUNC(void *, free); +static inline void freep(void *p) { + free(*(void**) p); +} #define _cleanup_free_ _cleanup_(freep) +DEFINE_TRIVIAL_CLEANUP_FUNC(int, close); +#define _cleanup_close_ _cleanup_(closep) + +DEFINE_TRIVIAL_CLEANUP_FUNC(FILE *, fclose); +#define _cleanup_fclose_ _cleanup_(fclosep) + +DEFINE_TRIVIAL_CLEANUP_FUNC(DIR *, closedir); +#define _cleanup_closedir_ _cleanup_(closedirp) + DEFINE_TRIVIAL_CLEANUP_FUNC(sd_bus *, sd_bus_unref); #define _cleanup_bus_unref_ _cleanup_(sd_bus_unrefp) -- cgit v1.2.3