-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmore_bul.c
68 lines (64 loc) · 1.05 KB
/
more_bul.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "shell.h"
/**
* history_dis - Display History Of User Input Simple Shell
* @c:Parsed Command
* @s:Statue Of Last Excute
* Return: 0 Succes -1 Fail
*/
int history_dis(__attribute__((unused))char **c, __attribute__((unused))int s)
{
char *filename = ".simple_shell_history";
FILE *fp;
char *line = NULL;
size_t len = 0;
int counter = 0;
char *er;
fp = fopen(filename, "r");
if (fp == NULL)
{
return (-1);
}
while ((getline(&line, &len, fp)) != -1)
{
counter++;
er = _itoa(counter);
PRINTER(er);
free(er);
PRINTER(" ");
PRINTER(line);
}
if (line)
free(line);
fclose(fp);
return (0);
}
/**
* print_echo - Excute Normal Echo
* @cmd: Parsed Command
* Return: 0 Succes -1 Fail
*/
int print_echo(char **cmd)
{
pid_t pid;
int status;
pid = fork();
if (pid == 0)
{
if (execve("/bin/echo", cmd, environ) == -1)
{
return (-1);
}
exit(EXIT_FAILURE);
}
else if (pid < 0)
{
return (-1);
}
else
{
do {
waitpid(pid, &status, WUNTRACED);
} while (!WIFEXITED(status) && !WIFSIGNALED(status));
}
return (1);
}