-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdate.c
51 lines (48 loc) · 1.12 KB
/
date.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
#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
#include<sys/types.h>
#include<sys/wait.h>
#include <string.h>
void date(char parsed[1000][1000]){
int i=0;
int j = 0;
int o = 0;
int s = 1;
int flag = 0;
char path[256] = {};
char options[256] ={};
while(i < 1000 && parsed[i][0]!='\n'){
if(flag==0 && strcmp(parsed[i],"date")==0){
flag = 1;
}
else if(flag==1 && parsed[i][0]=='-'){
options[0] = '-';
options[s] = parsed[i][1];
++s;
}
else if(flag == 1 && parsed[i][0]!='\0'){
while(i < 1000 && j<256 && parsed[i][j]!='\0'){
path[o] = parsed[i][j];
++j;++o;
}
j = 0;
}
++i;
}
pid_t pid;
pid = fork();
if(pid<0){
printf("%s\n" , "Some error occurred ");
}
else if(pid==0 && options[0]=='\0'){
execl("/bin/date","date",(char *)0);
}
else if(pid==0 && options[0]!='\0'){
execl("/bin/date","date",options,(char *)0);
}
else
{
wait(NULL);
}
}