aboutsummaryrefslogtreecommitdiff
path: root/src/str/ft_strdup.c
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2020-03-11 21:07:32 +0100
committerCharles <sircharlesaze@gmail.com>2020-03-11 21:23:49 +0100
commitc128213daa677d548bfc2905496257fe4a4faf79 (patch)
treed087ceaeff3124ff539bc05d834d79f8187d5628 /src/str/ft_strdup.c
parent3c3f1115f6e9a9b914e2dcbd796501ca7ce85342 (diff)
downloadlibft-c128213daa677d548bfc2905496257fe4a4faf79.tar.gz
libft-c128213daa677d548bfc2905496257fe4a4faf79.tar.bz2
libft-c128213daa677d548bfc2905496257fe4a4faf79.zip
ft_mem* and ft_strlen optimization
Diffstat (limited to 'src/str/ft_strdup.c')
-rw-r--r--src/str/ft_strdup.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/str/ft_strdup.c b/src/str/ft_strdup.c
index b248272..9493d82 100644
--- a/src/str/ft_strdup.c
+++ b/src/str/ft_strdup.c
@@ -11,12 +11,15 @@
/* ************************************************************************** */
#include "libft.h"
+#include "libft_str.h"
char *ft_strdup(const char *s)
{
char *clone;
+ size_t size;
- if ((clone = (char*)malloc(sizeof(char) * (ft_strlen(s) + 1))) == NULL)
+ size = ft_strlen(s) + 1;
+ if ((clone = (char*)malloc(sizeof(char) * size)) == NULL)
return (NULL);
- return (ft_strcpy(clone, s));
+ return (ft_memcpy(clone, s, size));
}