From c90834b8d41e062763289abb6135c71c49fddec4 Mon Sep 17 00:00:00 2001 From: Ranjani Sridharan Date: Wed, 31 Mar 2021 18:03:11 -0700 Subject: [PATCH 1/2] conf: Export snd_config_make_add() Create the snd_config_mak_add() and export it for use in the Topology2.0 pre-processor in alsatplg. Signed-off-by: Ranjani Sridharan --- include/conf.h | 2 ++ src/conf.c | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/include/conf.h b/include/conf.h index cf88f1bd..fde91ba2 100644 --- a/include/conf.h +++ b/include/conf.h @@ -124,6 +124,8 @@ int snd_config_copy(snd_config_t **dst, snd_config_t *src); int snd_config_make(snd_config_t **config, const char *key, snd_config_type_t type); +int snd_config_make_add(snd_config_t **config, char *id, + snd_config_type_t type, snd_config_t *parent); int snd_config_make_integer(snd_config_t **config, const char *key); int snd_config_make_integer64(snd_config_t **config, const char *key); int snd_config_make_real(snd_config_t **config, const char *key); diff --git a/src/conf.c b/src/conf.c index 1bcd65c8..1a760b89 100644 --- a/src/conf.c +++ b/src/conf.c @@ -2309,6 +2309,47 @@ int snd_config_make(snd_config_t **config, const char *id, return _snd_config_make(config, &id1, type); } +/** + * \brief Creates a configuration node and add it to the parent node. + * \param[out] config The function puts the handle to the new node at + * the address specified by \a config. + * \param[in] id The id of the new node. + * \param[in] type The type of the new node. + * \param[in] parent handle for the parent node. + * \return Zero if successful, otherwise a negative error code. + * + * This functions creates a new node of the specified type. + * The new node has id \a id, which may be \c NULL. + * and adds it to the parent node. + * + * The value of the new node is zero (for numbers), or \c NULL (for + * strings and pointers), or empty (for compound nodes). + * + * \par Errors: + *
+ *
-ENOMEM
Out of memory. + *
+ */ +int snd_config_make_add(snd_config_t **config, char *id, + snd_config_type_t type, snd_config_t *parent) +{ + char *id1; + int ret; + + assert(config); + if (id) { + id1 = strdup(id); + if (!id1) + return -ENOMEM; + } else + id1 = NULL; + ret = _snd_config_make(config, &id1, type); + if (ret < 0) + return ret; + + return snd_config_add(parent, *config); +} + /** * \brief Creates an integer configuration node. * \param[out] config The function puts the handle to the new node at From 7c6e35995441fa8832f951b1fd42fba9f8d385d4 Mon Sep 17 00:00:00 2001 From: Ranjani Sridharan Date: Wed, 31 Mar 2021 18:54:48 -0700 Subject: [PATCH 2/2] globa: Export snd_strlcpy() Export snd_strlcpy() for use in the Topology2.0 pre-processor in alsatplg. Signed-off-by: Ranjani Sridharan --- include/global.h | 13 +++++++++++++ include/local.h | 1 - 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/include/global.h b/include/global.h index 71a1b12f..89367004 100644 --- a/include/global.h +++ b/include/global.h @@ -153,6 +153,19 @@ typedef struct timeval snd_timestamp_t; /** Hi-res timestamp */ typedef struct timespec snd_htimestamp_t; +/** + * \brief Copy a C-string into a sized buffer + * \param dst Where to copy the string to + * \param src Where to copy the string from + * \param size Size of destination buffer + * \retval The source string length + * + * The result is always a valid NUL-terminated string that fits + * in the buffer (unless, of course, the buffer size is zero). + * It does not pad out the result like strncpy() does. + */ +size_t snd_strlcpy(char *dst, const char *src, size_t size); + /** \} */ #ifdef __cplusplus diff --git a/include/local.h b/include/local.h index ed6ba936..9d9deeac 100644 --- a/include/local.h +++ b/include/local.h @@ -236,7 +236,6 @@ int safe_strtol(const char *str, long *val); int snd_send_fd(int sock, void *data, size_t len, int fd); int snd_receive_fd(int sock, void *data, size_t len, int *fd); -size_t snd_strlcpy(char *dst, const char *src, size_t size); /* * error messages