push_swap/sources/error.c
2024-04-20 14:48:16 +02:00

53 lines
1.4 KiB
C
Executable file

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* error.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/13 12:08:13 by rparodi #+# #+# */
/* Updated: 2024/04/18 15:17:25 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
#include "../includes/push_swap.h"
void error_message(char *msg, t_list **maix, t_list **sb, char **s)
{
(void)msg;
write(2, "Error\n", 6);
if (maix)
free_stack(maix);
if (sb)
free_stack(sb);
if (s)
free_string(s);
exit(EXIT_FAILURE);
}
void free_string(char **str)
{
int i;
i = 0;
while (str[i])
i++;
while (i >= 0)
free(str[i--]);
free(str);
}
void free_stack(t_list **stack)
{
t_list *head;
t_list *tmp;
head = *stack;
while (head)
{
tmp = head;
head = head->next;
free(tmp);
}
free(stack);
}