[alsa-devel] [PATCH v2 07/13] topology: Add private data parser

Takashi Iwai tiwai at suse.de
Wed Jul 1 18:20:36 CEST 2015


At Wed,  1 Jul 2015 14:44:29 +0100,
Liam Girdwood wrote:
> 
> +static int tplg_parse_data_file(snd_config_t *cfg, struct tplg_elem *elem)
> +{
> +	struct snd_soc_tplg_private *priv = NULL;
> +	const char *value = NULL;
> +	char filename[MAX_FILE];
> +	char *env = getenv(ALSA_CONFIG_TPLG_VAR);
> +	FILE *fp;
> +	size_t size, bytes_read;
> +	int ret = 0;
> +
> +	tplg_dbg("data DataFile: %s\n", elem->id);
> +
> +	if (snd_config_get_string(cfg, &value) < 0)
> +		return -EINVAL;
> +
> +	/* prepend alsa config directory to path */
> +	snprintf(filename, sizeof(filename), "%s/%s",
> +		env ? env : ALSA_TPLG_DIR, value);
> +	filename[sizeof(filename)-1] = '\0';

Unlike strncpy(), snprintf() puts the NUL-character by itself, so this
is superfluous.

> +static int get_hex_num(const char *str)
> +{
> +	char *tmp, *s = NULL;
> +	int i = 0;
> +
> +	tmp = strdup(str);
> +	if (tmp == NULL)
> +		return -ENOMEM;
> +
> +	s = strtok(tmp, ",");
> +	while (s != NULL) {
> +		s = strtok(NULL, ",");
> +		i++;
> +	}
> +
> +	free(tmp);
> +	return i;

Hmm, this just counts the number of comma + 1, so you don't need to
duplicate the string?


Takashi


More information about the Alsa-devel mailing list