-
Notifications
You must be signed in to change notification settings - Fork 0
/
redirections.c
40 lines (37 loc) · 934 Bytes
/
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
#include"header.h"
#include"variables.h"
void input_redirection(char * line)
{
int i = 0;
char newline[1000];
for (i=0;i<strlen(line);i++)
newline[i] = line[i];
newline[i] = '\0';
char ** intemp = myparser(newline, "<");
if (intemp[1]!= NULL)
{
char ** temp = myparser(intemp[1], " ");
file_in = open(temp[0], O_RDONLY);
}
}
void output_redirection(char * line, int flag)
{
int i = 0;
char newline[1000];
for (i=0;i<strlen(line);i++)
newline[i] = line[i];
newline[i] = '\0';
char ** intemp = myparser(newline, ">");
if (intemp[1]!= NULL)
{
char ** temp = myparser(intemp[1]," ");
if (flag == 0) file_out = open(temp[0],O_TRUNC | O_WRONLY | O_CREAT, S_IRWXU);
else
{
file_out = open(temp[0], O_WRONLY | O_CREAT, S_IRWXU);
lseek(file_out, 0,SEEK_END);
}
}
else
file_out = 1;
}