/* Returns 0 if environment variable was added successfully or -ENOMEM if no space was available.  */
int add_uevent_var(struct kobj_uevent_env *env, const char *format,...)
/* Returns 0 if environment variable was added successfully or -ENOMEM if no space was available.  */
int add_uevent_var(struct kobj_uevent_env *env, const char *format,...)
{
	va_list args;
	int len;
	if (env->envp_idx >= ARRAY_SIZE(env->envp)) {
		WARN(1, KERN_ERR "add_uevent_var: too many keys\n");
		return -ENOMEM;
	}
	va_start(args, format);
	len = vsnprintf(&env->buf[env->buflen],
			sizeof(env->buf) - env->buflen,
			format, args);
	va_end(args);
	if (len >= (sizeof(env->buf) - env->buflen)) {
		WARN(1, KERN_ERR "add_uevent_var: buffer size too small\n");
		return -ENOMEM;
	}
	env->envp[env->envp_idx++] = &env->buf[env->buflen];
	env->buflen += len + 1;
	return 0;
}