Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
13 changes: 13 additions & 0 deletions include/global.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion include/local.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
41 changes: 41 additions & 0 deletions src/conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
* <dl>
* <dt>-ENOMEM<dd>Out of memory.
* </dl>
*/
int snd_config_make_add(snd_config_t **config, char *id,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be replaced with snd_config_make() + snd_config_add() calls. I don't think that we need to export another fcn for this functionality.

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
Expand Down