This repository has been archived by the owner on Oct 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prod_ressources.c
62 lines (53 loc) · 1.67 KB
/
prod_ressources.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* prod_ressources.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mgautier <mgautier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/10/12 11:00:42 by mgautier #+# #+# */
/* Updated: 2017/11/30 13:02:35 by mgautier ### ########.fr */
/* */
/* ************************************************************************** */
#include "prods_defs.h"
#include "libft.h"
#include <stdlib.h>
t_prod *create_prod(void)
{
t_prod *new;
new = malloc(sizeof(t_prod));
if (new != NULL)
new->sym_list = NULL;
return (new);
}
void destroy_prod(t_prod **to_destroy)
{
t_prod *prod;
prod = *to_destroy;
if (prod != NULL)
{
f_lstdel(&prod->sym_list, no_destroy);
free(prod);
*to_destroy = NULL;
}
}
void iter_del_prod(void **prod)
{
destroy_prod((t_prod**)prod);
}
static void *sym_cpy(void const *sym)
{
return ((void*)sym);
}
t_prod *dup_prod(t_prod const *prod)
{
t_prod *new_prod;
new_prod = malloc(sizeof(t_prod));
if (new_prod != NULL)
{
new_prod->sym_list = f_lstmap(prod->sym_list, sym_cpy, no_destroy);
if (new_prod->sym_list == NULL && prod->sym_list != NULL)
destroy_prod(&new_prod);
}
return (new_prod);
}