forked from erikaosgue/simple_shell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshell_prompt.c
More file actions
40 lines (37 loc) · 890 Bytes
/
shell_prompt.c
File metadata and controls
40 lines (37 loc) · 890 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
#include "shell.h"
/**
* shell_prompt - display the shell prompt, and use the issaty
* function for interactive and none interactive mode
* @count: The counter for every shell prompt display
* @exit_: integer with the last exit of a command
* Return: A struct with the buffer and the counter
*/
str_p shell_prompt(int count, int exit_)
{
str_p buf_count;
size_t bufersize = 0;
int bytes, len = 0;
char *buffer = NULL;
signal(SIGINT, ignore_signal);
if (isatty(STDIN_FILENO))
{
count++;
write(STDOUT_FILENO, "GreatTeam $ ", 12);
}
else
count++;
bytes = getline(&buffer, &bufersize, stdin);
if (bytes == EOF)
{
if (isatty(STDIN_FILENO))
write(STDOUT_FILENO, "\n", 1);
free(buffer);
exit(exit_);
}
len = _strlen(buffer);
if (buffer[len - 1] == '\n')
buffer[len - 1] = '\0';
buf_count.buffer = buffer;
buf_count.count = count;
return (buf_count);
}