aboutsummaryrefslogtreecommitdiff
path: root/ft_strndup.c
diff options
context:
space:
mode:
Diffstat (limited to 'ft_strndup.c')
-rw-r--r--ft_strndup.c19
1 files changed, 4 insertions, 15 deletions
diff --git a/ft_strndup.c b/ft_strndup.c
index d43c0ce..0d4119a 100644
--- a/ft_strndup.c
+++ b/ft_strndup.c
@@ -6,26 +6,15 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/25 03:28:52 by cacharle #+# #+# */
-/* Updated: 2019/10/25 03:36:24 by cacharle ### ########.fr */
+/* Updated: 2019/11/20 04:09:59 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
-#include <stdlib.h>
-#include <string.h>
+#include "libft.h"
char *ft_strndup(const char *s1, size_t n)
{
- char *clone;
- size_t i;
-
- if ((clone = (char*)malloc(sizeof(char) * (n + 1))) == NULL)
+ if ((clone = ft_strnew(n)) == NULL)
return (NULL);
- i = 0;
- while (i < n && s1[i])
- {
- clone[i] = s1[i];
- i++;
- }
- clone[i] = '\0';
- return (clone);
+ return (ft_strncpy(clone, s, n));
}