From d33652dad8838ab0a9175ca4613a3161ebc5676f Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 9 Aug 2011 11:20:31 +1000 Subject: [PATCH] config: return the new InputOption from add_option. Change add_option to return the new InputOption on success, or NULL failure. This way we can at least check for errors in callers. Signed-off-by: Peter Hutterer Reviewed-by: Daniel Stone --- config/config-backends.h | 2 +- config/config.c | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/config/config-backends.h b/config/config-backends.h index 0a2a22af0..0d36d7208 100644 --- a/config/config-backends.h +++ b/config/config-backends.h @@ -30,7 +30,7 @@ void remove_devices(const char *backend, const char *config_info); BOOL device_is_duplicate(const char *config_info); -void add_option(InputOption **options, const char *key, const char *value); +InputOption* add_option(InputOption **options, const char *key, const char *value); #ifdef CONFIG_UDEV int config_udev_init(void); diff --git a/config/config.c b/config/config.c index d86f7c649..af8f4f9b2 100644 --- a/config/config.c +++ b/config/config.c @@ -122,18 +122,25 @@ device_is_duplicate(const char *config_info) return FALSE; } -void +/** + * Allocate a new option and append to the list. + * + * @return A pointer to the newly allocated InputOption struct. + */ +InputOption* add_option(InputOption **options, const char *key, const char *value) { if (!value || *value == '\0') - return; + return NULL; for (; *options; options = &(*options)->next) ; *options = calloc(sizeof(**options), 1); if (!*options) /* Yeesh. */ - return; + return NULL; (*options)->key = strdup(key); (*options)->value = strdup(value); (*options)->next = NULL; + + return *options; }