From 782adcfd29c1d19a903b85e1519acf8902e00d2b Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Wed, 24 Jan 2018 09:05:00 +0100 Subject: [PATCH] signal.h: Introduce signal_array_getbyname() This is a nice utility function that actually does what most callers want, instead of signal_array_getbyid() which requires callers to come up with the signal id. Signed-off-by: Uli Schlachter --- common/signal.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/common/signal.h b/common/signal.h index 46bad94d0..390e5a8da 100644 --- a/common/signal.h +++ b/common/signal.h @@ -54,6 +54,13 @@ signal_array_getbyid(signal_array_t *arr, unsigned long id) return signal_array_lookup(arr, &sig); } +static inline signal_t * +signal_array_getbyname(signal_array_t *arr, const char *name) +{ + signal_t sig = { .id = a_strhash((const unsigned char *) NONULL(name)) }; + return signal_array_lookup(arr, &sig); +} + /** Connect a signal inside a signal array. * You are in charge of reference counting. * \param arr The signal array.