envlist_setenv(envlist_t *envlist, const char *env)

{

	struct envlist_entry *entry = NULL;

	const char *eq_sign;

	size_t envname_len;



	if ((envlist == NULL) || (env == NULL))

		return (EINVAL);



	/* find out first equals sign in given env */

	if ((eq_sign = strchr(env, '=')) == NULL)

		return (EINVAL);

	envname_len = eq_sign - env + 1;



	/*

	 * If there already exists variable with given name

	 * we remove and release it before allocating a whole

	 * new entry.

	 */

	for (entry = envlist->el_entries.lh_first; entry != NULL;

	    entry = entry->ev_link.le_next) {

		if (strncmp(entry->ev_var, env, envname_len) == 0)

			break;

	}



	if (entry != NULL) {

		LIST_REMOVE(entry, ev_link);

		free((char *)entry->ev_var);

		free(entry);

	} else {

		envlist->el_count++;

	}



	if ((entry = malloc(sizeof (*entry))) == NULL)

		return (errno);

	if ((entry->ev_var = strdup(env)) == NULL) {

		free(entry);

		return (errno);

	}

	LIST_INSERT_HEAD(&envlist->el_entries, entry, ev_link);



	return (0);

}

envlist_setenv(envlist_t *envlist, const char *env)

{

	struct envlist_entry *entry = NULL;

	const char *eq_sign;

	size_t envname_len;



	if ((envlist == NULL) || (env == NULL))

		return (EINVAL);



	

	if ((eq_sign = strchr(env, '=')) == NULL)

		return (EINVAL);

	envname_len = eq_sign - env + 1;



	









	for (entry = envlist->el_entries.lh_first; entry != NULL;

	    entry = entry->ev_link.le_next) {

		if (strncmp(entry->ev_var, env, envname_len) == 0)

			break;

	}



	if (entry != NULL) {

		LIST_REMOVE(entry, ev_link);

		free((char *)entry->ev_var);

		free(entry);

	} else {

		envlist->el_count++;

	}



	if ((entry = malloc(sizeof (*entry))) == NULL)

		return (errno);

	if ((entry->ev_var = strdup(env)) == NULL) {

		free(entry);

		return (errno);

	}

	LIST_INSERT_HEAD(&envlist->el_entries, entry, ev_link);



	return (0);

}

FUNC_0(envlist_t *VAR_0, const char *VAR_1)

{

	struct envlist_entry *VAR_2 = NULL;

	const char *VAR_3;

	size_t envname_len;



	if ((VAR_0 == NULL) || (VAR_1 == NULL))

		return (EINVAL);



	

	if ((VAR_3 = strchr(VAR_1, '=')) == NULL)

		return (EINVAL);

	envname_len = VAR_3 - VAR_1 + 1;



	









	for (VAR_2 = VAR_0->el_entries.lh_first; VAR_2 != NULL;

	    VAR_2 = VAR_2->ev_link.le_next) {

		if (strncmp(VAR_2->ev_var, VAR_1, envname_len) == 0)

			break;

	}



	if (VAR_2 != NULL) {

		LIST_REMOVE(VAR_2, ev_link);

		free((char *)VAR_2->ev_var);

		free(VAR_2);

	} else {

		VAR_0->el_count++;

	}



	if ((VAR_2 = malloc(sizeof (*VAR_2))) == NULL)

		return (errno);

	if ((VAR_2->ev_var = strdup(VAR_1)) == NULL) {

		free(VAR_2);

		return (errno);

	}

	LIST_INSERT_HEAD(&VAR_0->el_entries, VAR_2, ev_link);



	return (0);

}

FUNC_0(envlist_t *VAR_0, const char *VAR_1)
{ struct envlist_entry *VAR_2 = NULL; const char *VAR_3; size_t envname_len; if ((VAR_0 == NULL) || (VAR_1 == NULL))
return (EINVAL); if ((VAR_3 = strchr(VAR_1, '=')) == NULL)
return (EINVAL); envname_len = VAR_3 - VAR_1 + 1; for (VAR_2 = VAR_0->el_entries.lh_first; VAR_2 != NULL; VAR_2 = VAR_2->ev_link.le_next) { if (strncmp(VAR_2->ev_var, VAR_1, envname_len) == 0)
break; } if (VAR_2 != NULL) { LIST_REMOVE(VAR_2, ev_link); free((char *)VAR_2->ev_var); free(VAR_2); } else { VAR_0->el_count++; } if ((VAR_2 = malloc(sizeof (*VAR_2))) == NULL)
return (errno); if ((VAR_2->ev_var = strdup(VAR_1)) == NULL) { free(VAR_2); return (errno); } LIST_INSERT_HEAD(&VAR_0->el_entries, VAR_2, ev_link); return (0); }