forked from wendysegura/simple_shell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprompt.c
More file actions
63 lines (50 loc) · 1.02 KB
/
prompt.c
File metadata and controls
63 lines (50 loc) · 1.02 KB
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
#include "holberton.h"
/**
**prompt - interactive or non interactive
**@fd: stream
**@buff: buffer
**Return: void
**/
void prompt(int fd, struct stat buff)
{
fstat(fd, &buff);
if (is_interactive(fd, buff))
_puts(PROMPT);
}
/**
*_puts - put string to stdout
*@str: string to send to stdout
**/
void _puts(char *str)
{
unsigned int len;
len = _strlen(str);
write(STDOUT_FILENO, str, len);
}
/**
*_puts_err - output string to stderr
*@str: string to send to stderr
**/
void _puts_err(char *str)
{
unsigned int len;
len = _strlen(str);
write(STDERR_FILENO, str, len);
}
/**
** is_interactive - returns a "boolean" indicating wheather stream
** (typically STDIN_FILENO) is interactive or not
** NOTE: no guarantees on results if fd is not an input stream in
** general or STDIN_FILENO in particular
** @fd: file descriptor
** @buff: buffer
** Return: int
**/
int is_interactive(int fd, struct stat buff)
{
fstat(fd, &buff);
if (!(S_ISCHR(buff.st_mode)))
return (FALSE);
else
return (TRUE);
}