]> git.alsa-project.org Git - alsa-lib.git/commitdiff
conf: add snd_config_get_llong() helper
authorJaroslav Kysela <perex@perex.cz>
Fri, 31 Jul 2026 09:30:00 +0000 (11:30 +0200)
committerJaroslav Kysela <perex@perex.cz>
Fri, 31 Jul 2026 10:26:29 +0000 (12:26 +0200)
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 <perex@perex.cz>
include/conf.h
src/Versions.in.in
src/conf.c
src/ucm/ucm_repeat.c

index 827396c5dc8192ce4d8c84d7c483935270a82df8..c33b3e9bbf52159731906022ee0ee8f07b2e1acb 100644 (file)
@@ -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);
index 18f31f9d3016e399871b52e07f3303747b166466..efe1e62ba9485c99972072f22c3bde11d4820c75 100644 (file)
@@ -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;
index e1dba23dabeda04385ce34c8277f60c5ddfbf1d8..a27e6786e79e64437a0f6160b1e161595c52752e 100644 (file)
@@ -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:
+ * <dl>
+ * <dt>-EINVAL<dd>\a config is not an integer, integer64 or a parseable string node.
+ * </dl>
+ */
+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.
index e3e08e0c03d1addabf2c599c61fb9f9456c119b5..4e9a0c7c869fbe96cc0f97916f02e2fefefc10cf 100644 (file)
@@ -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;