-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsplit_pipes.c
More file actions
43 lines (42 loc) · 804 Bytes
/
split_pipes.c
File metadata and controls
43 lines (42 loc) · 804 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
#include<sys/types.h>
#include<fcntl.h>
#include<sys/stat.h>
#include<sys/wait.h>
#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
#include<string.h>
#include<dirent.h>
#include<time.h>
#include<pwd.h>
#include<grp.h>
#include<ctype.h>
#include "shellheader.h"
char** split_pipes(char* linegiven)
{
int buffer_size=64,pos=0;
char** splits=(char**)malloc(sizeof(char*)*buffer_size);
if(!splits)
{
fprintf(stderr,"allocation error\n");
exit(EXIT_FAILURE);
}
char* split=strtok(linegiven,"|");
while(split!=NULL)
{
splits[pos++]=split;
if(pos>=buffer_size)
{
buffer_size+=64;
splits=(char**)realloc(splits,buffer_size);
}
if(!splits)
{
fprintf(stderr,"allocation error\n");
exit(EXIT_FAILURE);
}
split=strtok(NULL,"|");
}
splits[pos]=NULL;
return splits;
}