-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathredirections.c
65 lines (59 loc) · 1.61 KB
/
redirections.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* redirections.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: antofern <antofern@student.42madrid.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/12/21 10:05:28 by antofern #+# #+# */
/* Updated: 2024/12/21 15:13:22 by antofern ### ########.fr */
/* */
/* ************************************************************************** */
#include "pipex.h"
//NO PROBADA
void infile_to_stdin(char *infile)
{
int fd;
fd = open(infile, O_RDONLY);
if (fd == -1)
{
ft_putstr_fd("pipex: ", 2);
perror(infile);
exit(1);
}
if (dup2(fd, STDIN_FILENO) == -1)
{
ft_putstr_fd("pipex: ", 2);
perror(NULL);
exit(1);
}
close(fd);
}
void stdout_to_outfile(char *outfile)
{
int fd;
fd = open(outfile, O_WRONLY | O_CREAT | O_TRUNC, 00664);
if (fd == -1)
{
ft_putstr_fd("pipex: ", 2);
perror(outfile);
exit(1);
}
if (dup2(fd, STDOUT_FILENO) == -1)
{
ft_putstr_fd("pipex: ", 2);
perror(NULL);
exit(1);
}
close(fd);
}
void stdout_to_pipe(t_pipe pip)
{
if (dup2(pip[1], STDOUT_FILENO) == -1)
{
ft_putstr_fd("pipex: ", 2);
perror(NULL);
exit(1);
}
close(pip[1]);
}