-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsignals.c
55 lines (49 loc) · 1.49 KB
/
signals.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
52
53
54
55
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* signals.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: btaha <btaha@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/29 19:38:30 by btaha #+# #+# */
/* Updated: 2023/01/13 21:10:39 by btaha ### ########.fr */
/* */
/* ************************************************************************** */
#include "./includes/minishell.h"
static void sig_int_handler(int sig)
{
rl_replace_line("", 0);
ft_putstr_fd("\n", 1);
if (g_shell.exec)
return ;
rl_on_new_line();
rl_redisplay();
g_shell.exit = 128 + sig;
}
static void sig_quit_handler(int sig)
{
if (!g_shell.exec)
return ;
rl_replace_line("", 0);
ft_printf(1, "Quit: %d\n", sig);
}
int set_sig(int catch_signals)
{
signal(SIGINT, sig_int_handler);
signal(SIGQUIT, sig_quit_handler);
if (catch_signals)
rl_catch_signals = 0;
return (0);
}
int event(void)
{
return (0);
}
void handler(int sig)
{
if (sig == SIGINT)
{
g_shell.exec = -1;
rl_done = 1;
}
}