-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathredirect.c
More file actions
47 lines (45 loc) · 793 Bytes
/
redirect.c
File metadata and controls
47 lines (45 loc) · 793 Bytes
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
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "header.h"
extern int redirect;
int check_redirect(char * pipe_command)
{
int i=0;
char * token;
char * tempcommand=strdup(pipe_command);
token=strtok(tempcommand," <>\t\a\r");
in=NULL;
out=NULL;
redirect=0;
while(token!=NULL)
{
if(!redirect)
{
argv[i]=strdup(token);
i++;
}
int pos=token-tempcommand+strlen(token);
char ch1=pipe_command[pos];
char ch2=pipe_command[pos+1];
token=strtok(NULL," <>\t\a\r");
if(ch1=='<' || ch2=='<')
{
in=token;
redirect=1;
}
if(ch1=='>' || ch2=='>')
{
out=token;
redirect=1;
}
}
argv[i]=NULL;
return redirect;
}