[ADD] redirection '>>'
also fix close_fds()
This commit is contained in:
		
							parent
							
								
									74564daa52
								
							
						
					
					
						commit
						c86126ec9d
					
				
					 2 changed files with 13 additions and 5 deletions
				
			
		|  | @ -6,7 +6,7 @@ | ||||||
| /*   By: mcolonna <marvin@42.fr>                    +#+  +:+       +#+        */ | /*   By: mcolonna <marvin@42.fr>                    +#+  +:+       +#+        */ | ||||||
| /*                                                +#+#+#+#+#+   +#+           */ | /*                                                +#+#+#+#+#+   +#+           */ | ||||||
| /*   Created: 2024/04/23 14:33:45 by mcolonna          #+#    #+#             */ | /*   Created: 2024/04/23 14:33:45 by mcolonna          #+#    #+#             */ | ||||||
| /*   Updated: 2024/05/01 11:35:54 by mcolonna         ###   ########.fr       */ | /*   Updated: 2024/05/02 15:20:41 by mcolonna         ###   ########.fr       */ | ||||||
| /*                                                                            */ | /*                                                                            */ | ||||||
| /* ************************************************************************** */ | /* ************************************************************************** */ | ||||||
| 
 | 
 | ||||||
|  | @ -18,10 +18,10 @@ t_memclass	g_mc; | ||||||
| static void	close_fds(const t_command *command) | static void	close_fds(const t_command *command) | ||||||
| { | { | ||||||
| 	if (command->input_fd != 0) | 	if (command->input_fd != 0) | ||||||
| 		if (close(command->input_fd) != -1) | 		if (close(command->input_fd) == -1) | ||||||
| 			minishell_error("errno"); | 			minishell_error("errno"); | ||||||
| 	if (command->output_fd != 1) | 	if (command->output_fd != 1) | ||||||
| 		if (close(command->output_fd) != -1) | 		if (close(command->output_fd) == -1) | ||||||
| 			minishell_error("errno"); | 			minishell_error("errno"); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -6,7 +6,7 @@ | ||||||
| /*   By: mcolonna <marvin@42.fr>                    +#+  +:+       +#+        */ | /*   By: mcolonna <marvin@42.fr>                    +#+  +:+       +#+        */ | ||||||
| /*                                                +#+#+#+#+#+   +#+           */ | /*                                                +#+#+#+#+#+   +#+           */ | ||||||
| /*   Created: 2024/04/24 13:47:40 by mcolonna          #+#    #+#             */ | /*   Created: 2024/04/24 13:47:40 by mcolonna          #+#    #+#             */ | ||||||
| /*   Updated: 2024/04/30 16:22:08 by mcolonna         ###   ########.fr       */ | /*   Updated: 2024/05/02 15:15:36 by mcolonna         ###   ########.fr       */ | ||||||
| /*                                                                            */ | /*                                                                            */ | ||||||
| /* ************************************************************************** */ | /* ************************************************************************** */ | ||||||
| 
 | 
 | ||||||
|  | @ -133,16 +133,24 @@ static int	get_inputfile(t_parsing_args *args, const char *stop_charset) | ||||||
| static int	get_outputfile(t_parsing_args *args, const char *stop_charset) | static int	get_outputfile(t_parsing_args *args, const char *stop_charset) | ||||||
| { | { | ||||||
| 	const char	*str; | 	const char	*str; | ||||||
|  | 	int			flag; | ||||||
| 
 | 
 | ||||||
| 	if (args->r.output_fd != 1) | 	if (args->r.output_fd != 1) | ||||||
| 		return (parse_error("several output files")); | 		return (parse_error("several output files")); | ||||||
| 	if (!stream_read(&args->stream)) | 	if (!stream_read(&args->stream)) | ||||||
| 		return (parse_error("EOF unexpected")); | 		return (parse_error("EOF unexpected")); | ||||||
|  | 	flag = O_TRUNC; | ||||||
|  | 	if (stream_read(&args->stream) == '>') | ||||||
|  | 	{ | ||||||
|  | 		stream_pop(&args->stream); | ||||||
|  | 		flag = O_APPEND; | ||||||
|  | 	} | ||||||
|  | 	skip_blank(&args->stream); | ||||||
| 	str = get_string(args, stop_charset); | 	str = get_string(args, stop_charset); | ||||||
| 	if (!str) | 	if (!str) | ||||||
| 		return (parse_error("EOF unexpected")); | 		return (parse_error("EOF unexpected")); | ||||||
| 	args->r.output_fd = open( | 	args->r.output_fd = open( | ||||||
| 			str, O_WRONLY | O_CREAT | O_TRUNC, 0666); | 			str, O_WRONLY | O_CREAT | flag, 0666); | ||||||
| 	if (args->r.output_fd == -1) | 	if (args->r.output_fd == -1) | ||||||
| 		return (perror(str), errno); | 		return (perror(str), errno); | ||||||
| 	return (0); | 	return (0); | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 mcolonna
						mcolonna