aboutsummaryrefslogtreecommitdiff
path: root/src/str/ft_strnew.c
diff options
context:
space:
mode:
authorCharles Cabergs <me@cacharle.xyz>2020-08-02 11:05:33 +0200
committerCharles Cabergs <me@cacharle.xyz>2020-08-02 11:05:33 +0200
commit5d2f925b20ceaea4122c59d2d2c4e7d4ae991fde (patch)
tree80911dc3c32e9f230750e7e1042d413dfb6efab2 /src/str/ft_strnew.c
parentee32953ea79616e72f5428cdf40c834714a891c9 (diff)
parentb96b82194ccad2cddbb46b77aa1962a57c47ff44 (diff)
downloadlibft-5d2f925b20ceaea4122c59d2d2c4e7d4ae991fde.tar.gz
libft-5d2f925b20ceaea4122c59d2d2c4e7d4ae991fde.tar.bz2
libft-5d2f925b20ceaea4122c59d2d2c4e7d4ae991fde.zip
Merge branch 'master' into ft_ssl
Diffstat (limited to 'src/str/ft_strnew.c')
-rw-r--r--src/str/ft_strnew.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/str/ft_strnew.c b/src/str/ft_strnew.c
index 1bca6d5..f0d2221 100644
--- a/src/str/ft_strnew.c
+++ b/src/str/ft_strnew.c
@@ -6,13 +6,26 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/07 10:17:34 by cacharle #+# #+# */
-/* Updated: 2019/11/20 03:16:14 by cacharle ### ########.fr */
+/* Updated: 2020/05/11 15:28:15 by charles ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
-char *ft_strnew(size_t size)
+/*
+** \brief Create a new null-terminated string
+** \param len String length
+** \return Allocated string or NULL is allocation failed
+** \note This implementation doesn't follow the subject
+** because zeroing every byte is too inefficient
+*/
+
+char *ft_strnew(size_t len)
{
- return ((char*)ft_calloc(size + 1, sizeof(char)));
+ char *s;
+
+ if ((s = (char*)malloc(sizeof(char) * (len + 1))) == NULL)
+ return (NULL);
+ s[len] = '\0';
+ return (s);
}