-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathshell.c
More file actions
43 lines (42 loc) · 676 Bytes
/
shell.c
File metadata and controls
43 lines (42 loc) · 676 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 "shell.h"
/**
*main - program that creates a prompt, recieves input and calls
*forking function when needed.
*Return: Always zero
*/
int main(void)
{
char *buf = NULL;
char *e = "exit\n";
char *env = "env\n";
size_t l = 0;
ssize_t c = 0;
int i = 0;
while (1)
{
i = isatty(STDIN_FILENO);
if (i == 1)
write(STDOUT_FILENO, "$ ", 2);
c = getline(&buf, &l, stdin);
if (c == -1)
{
if (i == 1)
write(STDOUT_FILENO, "\n", 1);
free(buf);
exit(0);
}
if (_strcmp(buf, e) == 0)
{
free(buf);
exit(0);
}
if (_strcmp(buf, env) == 0)
printenv();
else if (c > 1)
{
buf[c - 1] = '\0';
_forkIt(buf);
}
}
return (0);
}