-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.c
More file actions
49 lines (40 loc) · 801 Bytes
/
main.c
File metadata and controls
49 lines (40 loc) · 801 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
44
45
46
47
48
49
#include "main.h"
/**
* main - implements super simple shell
*
* @ac: number of commandline arguments
* @av: array of commandline arguments
* @env: array of environment variables
*
* Return: 0 success. 1 otherwise
*/
int main(int ac, char **av, char **env)
{
list_t *env_list = NULL;
int shell_return;
/* create env_list */
env_list = create_env(env, env_list);
/* handle SIGINT */
signal(SIGINT, sig_handler);
/* start shell */
shell_return = shell(env_list, av[0]);
/*check return value of shell */
if (shell_return)
{
free_list(env_list);
exit(shell_return);
}
(void)ac;
free_list(env_list);
return (0);
}
/**
* sig_handler - handles SIGINT
* @sig: SIGINT
*/
void sig_handler(int sig)
{
signal(sig, sig_handler);
write(STDOUT_FILENO, "\n", 2);
prompt();
}