示例#1
0
文件: init.c 项目: Monitob/shell_soul
t_env		*put_in_list(t_env *root, char *param)
{
	t_env	*new_env;

	if ((new_env = (t_env *)malloc(sizeof(t_env))) == NULL)
		return ((t_env *)ft_error_null("Error, couldn't malloc\n"));
	new_env->num = root->prev->num + 1;
	new_env->prev = root->prev;
	new_env->next = root;
	root->prev->next = new_env;
	root->prev = new_env;
	if (!(new_env->var = ft_strdup(param)))
		return ((t_env *)ft_error_null("Error, couldn't strdup\n"));
	new_env->pos = -1;
	return (new_env);
}
示例#2
0
文件: ft_lstiter.c 项目: NobuX/42
void	ft_lstiter(t_list *lst, void (*f) (t_list *elem))
{
	if (!(lst) || !(f))
		ft_error_null("ft_lstiter");
	else
		while (lst)
		{
			f(lst);
			lst = lst->next;
		}
}
示例#3
0
char	*ft_malloc(int size)
{
	int		i;
	char	*str;

	i = 0;
	str = malloc(size);
	if (str == NULL)
		return (ft_error_null("Fail malloc"));
	while (i < size)
		str[i++] = '\0';
	return (str);
}
示例#4
0
文件: init.c 项目: Monitob/shell_soul
t_env		*get_root(void)
{
	t_env	*root;

	if ((root = (t_env *)malloc(sizeof(t_env))) == NULL)
		return ((t_env *)ft_error_null("Error, couldn't malloc\n"));
	root->next = root;
	root->prev = root;
	root->var = NULL;
	root->pos = 1;
	root->num = 0;
	return (root);
}
示例#5
0
文件: ft_strequ.c 项目: NobuX/42
int		ft_strequ(char const *s1, char const *s2)
{
	size_t count;

	count = 0;
	if (!(s1) || !(s2))
		return ((int)ft_error_null("ft_strequ"));
	while (s1[count] && s2[count])
	{
		if (s1[count] != s2[count])
			return (0);
		count++;
	}
	return (1);
}
示例#6
0
char	*ft_realloc(char *cmd, int size)
{
	int		i;
	char	*new_cmd;

	i = 0;
	new_cmd = malloc(size);
	if (new_cmd == NULL)
		return (ft_error_null("Fail malloc()"));
	while (cmd[i])
	{
		new_cmd[i] = cmd[i];
		i++;
	}
	while (i < size)
		new_cmd[i++] = '\0';
	free(cmd);
	return (new_cmd);
}
示例#7
0
文件: ft_strmapi.c 项目: NobuX/42
char	*ft_strmapi(char const *s, char (*f) (unsigned int, char))
{
	char			*str;
	unsigned int	i;

	i = -1;
	if (!s || !f)
	{
		ft_error_null("ft_strmapi");
		return (NULL);
	}
	if ((str = ft_strnew(ft_strlen(s))))
	{
		while (s[++i])
			str[i] = f(i, s[i]);
		return (str);
	}
	ft_error_malloc("ft_strmapi");
	return (NULL);
}