You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
1.7 KiB

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mea <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/03 08:57:53 by narnaud #+# #+# */
/* Updated: 2022/05/24 08:30:44 by narnaud ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int is_empty(char *line)
{
while (*line)
{
if (*line < 9 || (*line > 13 && *line != 32))
return (0);
line++;
}
return (1);
}
int handle_status(t_datas *datas, int status)
3 years ago
{
int ret;
3 years ago
if (WIFSIGNALED(status))
3 years ago
{
ret = 128 + WTERMSIG(status);
3 years ago
if (datas->exit_code == 131)
printf("Quit: 3\n");
3 years ago
}
else
ret = WEXITSTATUS(status);
return (ret);
3 years ago
}
void nothing(int sig_num)
{
(void)sig_num;
}
3 years ago
void sigs_handler(int sig_num)
{
if (sig_num == SIGINT)
printf("\n");
rl_on_new_line();
rl_replace_line("", 0);
rl_redisplay();
return ;
}
void halt(t_datas *datas, int ret_code, int silent)
3 years ago
{
3 years ago
int i;
i = 0;
while (datas->envp[i])
{
free(datas->envp[i]);
i++;
}
free(datas->envp);
clear_history();
if (!silent)
printf("exit\n");
if (silent)
exit(datas->exit_code);
3 years ago
exit(ret_code);
}