forked from mistWil/holbertonschool-simple_shell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshell.c
51 lines (44 loc) · 701 Bytes
/
shell.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
#define _GNU_SOURCE
#include "shell.h"
/**
* main - program that mimic a super simple shell)
*
* Return: 0
*/
int main(void)
{
char *line = NULL;
while (1)
{
if (isatty(STDIN_FILENO) == 1)
{
printf("$ ");
fflush(stdout);
}
line = read_line();
split_line(line);
free(line);
}
return (0);
}
/**
* read_line - function to read the user inputs
* @void
*
* Return: char
*/
char *read_line(void)
{
char *line = NULL;
ssize_t bytes_read;
size_t buff_size = 0;
bytes_read = getline(&line, &buff_size, stdin);
if (bytes_read == EOF)
{
free(line);
exit(0);
}
if (bytes_read > 0 && line[bytes_read - 1] == '\n')
line[bytes_read - 1] = '\0';
return (line);
}