forked from alzheimeer/shell_v2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathredirection.c
More file actions
50 lines (48 loc) · 1.32 KB
/
Copy pathredirection.c
File metadata and controls
50 lines (48 loc) · 1.32 KB
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
#include "hsh.h"
/**
* redireccion - locate sings of redirection and #
* @info: structur
* Return: none
*/
void redireccion(info_t *info)
{
int j;
info->dup_stdin = dup(STDIN_FILENO), info->dup_stdout = dup(STDOUT_FILENO);
j = _strtoken(info->tokens);
if (info->ident == REOUTDOBLE || info->ident == REOUT || info->ident == REIN)
{
info->filename = info->tokens[j - 1];
info->tokens[j - 1] = NULL;
}
if (info->ident == REOUTDOBLE)
{
info->redirfilefd = open(info->filename, O_CREAT |
O_WRONLY | O_APPEND, 0666);
dup2(info->redirfilefd, STDOUT_FILENO), close(info->redirfilefd);
}
else if (info->ident == REOUT)
{
info->redirfilefd = open(info->filename, O_CREAT |
O_WRONLY | O_TRUNC, 0666);
dup2(info->redirfilefd, STDOUT_FILENO), close(info->redirfilefd);
}
else if (info->ident == REINDOBLE)
{
printf("no se para que es esto");
}
else if (info->ident == REIN)
{
info->redirfilefd2 = open_file(info, info->filename, 0);
if (info->redirfilefd2 == -1)
{
info->count++;
if (errno == EACCES)
fprintf(stderr, "%s: %d: cannot %s: Permission denied\n"
, info->fname, info->count, info->filename);
else if (errno == ENOENT)
fprintf(stderr, "%s: %d: cannot open %s: No such file\n"
, info->fname, info->count, info->filename); }
else
dup2(info->redirfilefd2, STDIN_FILENO);
}
}