Push the final version
This commit is contained in:
commit
d0fe1fb2fb
28 changed files with 1459 additions and 0 deletions
53
sources/error.c
Executable file
53
sources/error.c
Executable file
|
|
@ -0,0 +1,53 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* 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);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue