This commit is contained in:
2024-03-25 20:41:05 +01:00
parent 50dd393b36
commit c5b6f8f53e
4 changed files with 43 additions and 17 deletions

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/02 21:59:20 by tomoron #+# #+# */
/* Updated: 2024/03/25 13:19:26 by tomoron ### ########.fr */
/* Updated: 2024/03/25 20:04:03 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
@ -71,8 +71,31 @@ t_env *get_env(char **envp)
return (env);
}
void print_binary(unsigned int num)
{
if (num == 0) {
printf("0");
return;
}
// Taille d'un unsigned int en bits
int size = sizeof(unsigned int) * 8;
int i;
// Parcours de chaque bit de droite à gauche
for (i = size - 1; i >= 0; i--) {
// Vérifie si le bit est 1 ou 0
if (num & (1u << i))
printf("1");
else
printf("0");
}
}
int init_minishell(t_msh **msh, int argc, char **argv, char **envp)
{
struct termios t_p;
*msh = ft_calloc(1, sizeof(t_msh));
if (!*msh)
ft_exit(*msh, 1);
@ -81,6 +104,11 @@ int init_minishell(t_msh **msh, int argc, char **argv, char **envp)
(*msh)->env = get_env(envp);
signal(SIGINT, signal_handler_interactive);
signal(SIGQUIT, signal_handler_interactive);
if(tcgetattr(1, &t_p))
ft_printf_fd(2, "an error occured while setting the flags");
t_p.c_lflag = t_p.c_lflag & (~ECHOCTL);
if(tcsetattr(1, TCSANOW, &t_p))
ft_printf_fd(2, "an error occured while setting the flags");
return (0);
}