env 찾기


char	*search_env(char *key)
{
	int i;
	
	i = -1;
	while (g_envs[++i])
	{
		if (ft_strncmp(key, g_envs[i], ft_strlen(key)) == 0 &&
				g_envs[i][ft_strlen(key)] == '=')
			return (&g_envs[i][ft_strlen(key) + 1]);
	}
	return (NULL);
}

env key값 가져오기


char	*get_key(char *obj)
{
	int		size_key;
	char	*key;

	if (ft_strchr(obj, '=') == 0)
		size_key = ft_strlen(obj) + 1;
	else
		size_key = ft_strchr(obj, '=') - obj + 1;
	if (size_key - 1 != check_validkey(obj)) //size_key는 널포인터 자리 포함 길이. check_validkey는 순수 key의 길이.
		return (NULL); //key값에 유효하지 않은 문자 존재
	key = (char *)malloc(sizeof(char) * size_key);
	ft_strlcpy(key, obj, size_key);
	return (key);
}

env key값 유효성 확인


int		check_validkey(char *obj)
{
	int	cnt;

	cnt = 0;
	if (ft_isdigit(obj[0]))
		return (0);
	while (obj[cnt] && (ft_isalnum(obj[cnt]) || obj[cnt] == '_'))
		cnt++;
	return (cnt);
}

<aside> ‼️ key값으로는 숫자, 문자, _만 가능한 듯.

</aside>

env 정렬