OSDN Git Service

conf: add snd_config_is_empty() function
authorJaroslav Kysela <perex@perex.cz>
Thu, 13 May 2021 08:59:43 +0000 (10:59 +0200)
committerJaroslav Kysela <perex@perex.cz>
Thu, 13 May 2021 08:59:47 +0000 (10:59 +0200)
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
include/conf.h
src/conf.c

index e729fb0..5c70ebc 100644 (file)
@@ -141,6 +141,7 @@ int snd_config_imake_pointer(snd_config_t **config, const char *key, const void
 
 snd_config_type_t snd_config_get_type(const snd_config_t *config);
 int snd_config_is_array(const snd_config_t *config);
+int snd_config_is_empty(const snd_config_t *config);
 
 int snd_config_set_id(snd_config_t *config, const char *id);
 int snd_config_set_integer(snd_config_t *config, long value);
index 72422f1..7ebf757 100644 (file)
@@ -1833,6 +1833,19 @@ int snd_config_is_array(const snd_config_t *config)
 }
 
 /**
+ * \brief Returns if the compound has no fields (is empty).
+ * \param config Handle to the configuration node.
+ * \return A positive value when true, zero when false, otherwise a negative error code.
+ */
+int snd_config_is_empty(const snd_config_t *config)
+{
+       assert(config);
+       if (config->type != SND_CONFIG_TYPE_COMPOUND)
+               return -EINVAL;
+       return list_empty(&config->u.compound.fields);
+}
+
+/**
  * \brief Returns the id of a configuration node.
  * \param[in] config Handle to the configuration node.
  * \param[out] id The function puts the pointer to the id string at the