diff options
| -rw-r--r-- | include/libft_ht.h | 4 | ||||
| -rw-r--r-- | src/ht/ft_htset_safe.c | 25 |
2 files changed, 28 insertions, 1 deletions
diff --git a/include/libft_ht.h b/include/libft_ht.h index c53ee4d..91aa153 100644 --- a/include/libft_ht.h +++ b/include/libft_ht.h @@ -6,7 +6,7 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/01/31 10:36:09 by cacharle #+# #+# */ -/* Updated: 2020/04/04 22:34:53 by charles ### ########.fr */ +/* Updated: 2020/09/09 15:47:22 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -54,6 +54,8 @@ void ft_htdestroy(t_ftht *ht, t_ftdel_func del); void *ft_htget(t_ftht *ht, char *key); t_ftht_entry *ft_htset(t_ftht *ht, char *key, void *value, t_ftdel_func del); +t_ftht_entry *ft_htset_safe(t_ftht *ht, char *key, void *value, + t_ftdel_func del); void ft_htdelone(t_ftht *ht, char *key, t_ftdel_func del); t_ftht_entry *ft_htentry_new(char *key, void *value); void ft_htiter(t_ftht *ht, void (*f)(t_ftht_entry*)); diff --git a/src/ht/ft_htset_safe.c b/src/ht/ft_htset_safe.c new file mode 100644 index 0000000..fd132d2 --- /dev/null +++ b/src/ht/ft_htset_safe.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_htset_safe.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: charles <me@cacharle.xyz> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/09/09 15:46:10 by charles #+# #+# */ +/* Updated: 2020/09/09 15:46:24 by charles ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft_ht.h" + +t_ftht_entry *ft_htset_safe( + t_ftht *ht, + char *key, + void *value, + void (*del)(void*) +) +{ + if (value == NULL) + return (NULL); + return (ft_htset(ht, key, value, del)); +} |
