コード例 #1
0
ファイル: invalid_argument.c プロジェクト: acazuc/42_corewar
void			invalid_argument(t_parser *p, char expected, char got)
{
	char	*error_msg;

	if (expected & got)
		return ;
	error_msg = "Invalid arg, expected ";
	if (!(error_msg = ft_strjoin(error_msg, get_expected_chars(expected))))
		ERROR("Failed to malloc invalid arg expected msg");
	if (!(error_msg = ft_strjoin_free1(error_msg, ", got ")))
		ERROR("Failed to malloc invalid arg msg");
	if (!(error_msg = ft_strjoin_free1(error_msg, get_expected_chars(got))))
		ERROR("Failed to malloc invalid arg got msg");
	parse_error(p, error_msg);
}
コード例 #2
0
ファイル: get_next_line.c プロジェクト: acazuc/42_lem_in
static int	get_next_line_main(t_gnl *e)
{
	long			eol_i;
	int				readed;
	char			*buffer;
	int				has_readed;

	has_readed = 0;
	if (!(buffer = malloc(sizeof(*buffer) * BUFF_SIZE + 1)))
		return (-1);
	while ((readed = read(e->fd, buffer, BUFF_SIZE)) != -1)
	{
		if (readed == 0 && !has_readed)
			return (0);
		has_readed = 1;
		buffer[readed] = '\0';
		if ((eol_i = get_eol(buffer)) != -1 || readed < BUFF_SIZE)
		{
			return (get_next_line_main_part(e, buffer, eol_i, readed));
		}
		if (!(*(e->line) = ft_strjoin_free1(*(e->line), buffer)))
			return (-1);
	}
	free(buffer);
	return (-1);
}
コード例 #3
0
char	*load_file_loul(char *name, t_directory *dir)
{
	char	*tmp;

	if (name[0] == '/')
		return (ft_strdup(name));
	if (!(tmp = ft_strjoin(dir->path, "/")))
		error_quit("Failed to malloc string");
	if (!(tmp = ft_strjoin_free1(tmp, name)))
		error_quit("Failed to malloc string");
	return (tmp);
}