From 5a7ce39cda06b709c963e9234ea3fb2ed26413b6 Mon Sep 17 00:00:00 2001 From: Jaroslav Kysela Date: Fri, 31 Jul 2026 11:30:00 +0200 Subject: [PATCH] conf: add snd_config_get_llong() helper Add a snd_config_get_integer64()-style accessor that also accepts string nodes parsed as a number with a caller-supplied base, and use it in ucm_repeat.c's get_integer() helper instead of duplicating the type dispatch. Signed-off-by: Jaroslav Kysela --- include/conf.h | 1 + src/Versions.in.in | 6 ++++++ src/conf.c | 34 ++++++++++++++++++++++++++++++++++ src/ucm/ucm_repeat.c | 17 +---------------- 4 files changed, 42 insertions(+), 16 deletions(-) diff --git a/include/conf.h b/include/conf.h index 827396c5..c33b3e9b 100644 --- a/include/conf.h +++ b/include/conf.h @@ -181,6 +181,7 @@ int snd_config_get_integer(const snd_config_t *config, long *value); int snd_config_get_integer64(const snd_config_t *config, long long *value); int snd_config_get_real(const snd_config_t *config, double *value); int snd_config_get_ireal(const snd_config_t *config, double *value); +int snd_config_get_llong(const snd_config_t *config, long long *value, int base); int snd_config_get_string(const snd_config_t *config, const char **value); int snd_config_get_ascii(const snd_config_t *config, char **value); int snd_config_get_pointer(const snd_config_t *config, const void **value); diff --git a/src/Versions.in.in b/src/Versions.in.in index 18f31f9d..efe1e62b 100644 --- a/src/Versions.in.in +++ b/src/Versions.in.in @@ -228,3 +228,9 @@ ALSA_1.2.15 { @SYMBOL_PREFIX@snd_lib_log_filter; @SYMBOL_PREFIX@snd_lib_check; } ALSA_1.2.13; + +ALSA_1.2.17 { + global: + + @SYMBOL_PREFIX@snd_config_get_llong; +} ALSA_1.2.15; diff --git a/src/conf.c b/src/conf.c index e1dba23d..a27e6786 100644 --- a/src/conf.c +++ b/src/conf.c @@ -3257,6 +3257,40 @@ int snd_config_get_ireal(const snd_config_t *config, double *ptr) return 0; } +/** + * \brief Returns the value of an integer or string configuration node as a long long. + * \param[in] config Handle to the configuration node. + * \param[out] ptr The node's value. + * \param[in] base The numeric base used to parse a string node (see \c strtoll()). + * \return Zero if successful, otherwise a negative error code. + * + * If the node's type is integer or integer64, the value is converted + * to the \c long \c long type on the fly. If the node's type is string, + * the string is parsed as a number using \a base. + * + * \par Errors: + *
+ *
-EINVAL
\a config is not an integer, integer64 or a parseable string node. + *
+ */ +int snd_config_get_llong(const snd_config_t *config, long long *ptr, int base) +{ + const char *str; + + assert(config && ptr); + if (config->type == SND_CONFIG_TYPE_INTEGER) + *ptr = config->u.integer; + else if (config->type == SND_CONFIG_TYPE_INTEGER64) + *ptr = config->u.integer64; + else if (config->type == SND_CONFIG_TYPE_STRING) { + str = config->u.string; + if (str == NULL || safe_strtoll_base(str, ptr, base) < 0) + return -EINVAL; + } else + return -EINVAL; + return 0; +} + /** * \brief Returns the value of a string configuration node. * \param[in] config Handle to the configuration node. diff --git a/src/ucm/ucm_repeat.c b/src/ucm/ucm_repeat.c index e3e08e0c..4e9a0c7c 100644 --- a/src/ucm/ucm_repeat.c +++ b/src/ucm/ucm_repeat.c @@ -38,28 +38,13 @@ static int get_string(snd_config_t *compound, const char *key, const char **str) */ static int get_integer(snd_config_t *compound, const char *key, long long *val) { - snd_config_type_t t; snd_config_t *node; - const char *str; int err; err = snd_config_search(compound, key, &node); if (err < 0) return err; - t = snd_config_get_type(node); - if (t == SND_CONFIG_TYPE_INTEGER) { - long i; - err = snd_config_get_integer(node, &i); - if (err >= 0) - *val = i; - } else if (t == SND_CONFIG_TYPE_INTEGER64) { - err = snd_config_get_integer64(node, val); - } else { - err = snd_config_get_string(node, &str); - if (err < 0) - return err; - err = safe_strtoll(str, val); - } + err = snd_config_get_llong(node, val, 0); if (err < 0) return -EINVAL; -- 2.52.0