improve gexit with init function and add basic mlx image gestion
This commit is contained in:
@@ -1,10 +1,43 @@
|
||||
#include "cube3d.h"
|
||||
|
||||
static int comp_addr(void *to_find, void *to_compare)
|
||||
/*
|
||||
* gexit_init
|
||||
*
|
||||
*/
|
||||
|
||||
//-------------------------------
|
||||
// gexit function
|
||||
//-------------------------------
|
||||
typedef void(*func_to_gexit)(void*);
|
||||
|
||||
typedef struct s_exit
|
||||
{
|
||||
return (to_find == to_compare);
|
||||
func_to_gexit f;
|
||||
void *param;
|
||||
} t_exit;
|
||||
|
||||
|
||||
t_exit **exit_func()
|
||||
{
|
||||
static t_exit *texit = NULL;
|
||||
|
||||
if (!texit)
|
||||
texit = gmalloc(sizeof(t_exit));
|
||||
return (&texit);
|
||||
}
|
||||
|
||||
void gexit_init(void(*f)(void*), void *param)
|
||||
{
|
||||
t_exit **texit;
|
||||
|
||||
texit = exit_func();
|
||||
(*texit)->param = param;
|
||||
(*texit)->f = f;
|
||||
}
|
||||
|
||||
//-------------------------------
|
||||
// allocation list
|
||||
//-------------------------------
|
||||
t_list **alloc_lst()
|
||||
{
|
||||
static t_list *lst = NULL;
|
||||
@@ -12,6 +45,9 @@ t_list **alloc_lst()
|
||||
return (&lst);
|
||||
}
|
||||
|
||||
//-------------------------------
|
||||
// alloc, free, exit functions
|
||||
//-------------------------------
|
||||
void *gmalloc(size_t size)
|
||||
{
|
||||
void *tmp;
|
||||
@@ -26,6 +62,11 @@ void *gmalloc(size_t size)
|
||||
return (tmp);
|
||||
}
|
||||
|
||||
static int comp_addr(void *to_find, void *to_compare)
|
||||
{
|
||||
return (to_find == to_compare);
|
||||
}
|
||||
|
||||
void gfree(void *addr)
|
||||
{
|
||||
t_list **lst;
|
||||
@@ -41,8 +82,12 @@ void gfree(void *addr)
|
||||
void gexit(char *str)
|
||||
{
|
||||
t_list **lst;
|
||||
t_exit **texit;
|
||||
|
||||
lst = alloc_lst();
|
||||
texit = exit_func();
|
||||
if ((*texit)->f)
|
||||
(*texit)->f((*texit)->param);
|
||||
ft_putstr_fd(str, 2);
|
||||
ft_lstfree((*lst), free);
|
||||
exit(0);
|
||||
Reference in New Issue
Block a user