diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2019-12-27 17:24:35 +0100 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2019-12-27 17:24:35 +0100 |
commit | fc29371a10bf6cfd93c4e9ccfe9193c1311efc98 (patch) | |
tree | e5e67174f06e99d945fa2631bbd0648e1fafeec1 /libft/src/ft_strdup.c | |
parent | STDIN corrected (diff) | |
download | 42-minishell-fc29371a10bf6cfd93c4e9ccfe9193c1311efc98.tar.gz 42-minishell-fc29371a10bf6cfd93c4e9ccfe9193c1311efc98.tar.bz2 42-minishell-fc29371a10bf6cfd93c4e9ccfe9193c1311efc98.tar.xz 42-minishell-fc29371a10bf6cfd93c4e9ccfe9193c1311efc98.tar.zst 42-minishell-fc29371a10bf6cfd93c4e9ccfe9193c1311efc98.zip |
updated libft, better Makefile and .gitignore
Diffstat (limited to 'libft/src/ft_strdup.c')
-rw-r--r-- | libft/src/ft_strdup.c | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/libft/src/ft_strdup.c b/libft/src/ft_strdup.c index ce74fb5..830c965 100644 --- a/libft/src/ft_strdup.c +++ b/libft/src/ft_strdup.c @@ -11,21 +11,25 @@ /* / */ /* ************************************************************************** */ -#include "libft.h" +#include <libft.h> #include <stdlib.h> char *ft_strdup(const char *s1) { + char *n_str; size_t slen; - char *new_str; + size_t i; - new_str = ""; slen = ft_strlen(s1); - new_str = (char *)malloc((slen + 1) * sizeof(char)); - if (new_str == NULL) + if (!(n_str = (char*)malloc((slen + 1) * sizeof(char)))) return (NULL); - ft_memcpy(new_str, s1, slen); - new_str[slen] = '\0'; - return (new_str); + i = 0; + while (s1[i]) + { + n_str[i] = s1[i]; + i++; + } + n_str[i] = '\0'; + return (n_str); } |