-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_shell_mode.c
More file actions
31 lines (26 loc) · 850 Bytes
/
check_shell_mode.c
File metadata and controls
31 lines (26 loc) · 850 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
#include"shell.h"
/**
* check_shell_mode - check shell mode
* based on the number of command-line arguments (argc)
* @argc: arguments counter
* Return:-1 in case of error
* 0 if non interactive mode
* 1 if interactive mode
*/
int check_shell_mode(int argc)
{
struct stat stat_stdin;
/* system call to get info about file associated with file descriptor */
fstat(STDIN_FILENO, &stat_stdin);
/* and standard input is a terminal */
if (argc == 1 && isatty(STDIN_FILENO))
return (INTERACTIVE_MODE);
/* only one command-line and standard input is not a terminal */
if (argc == 1 && !isatty(STDIN_FILENO))
return (NON_INTERACTIVE_PIPE);/* non-interactive mode,reading from a pipe. */
/* there is at least one command-line argument */
if ((argc >= 1))
return (NON_INTERACTIVE_MODE);
/* unknown mode error */
return (ERROR);
}