diff options
| author | Charles Cabergs <me@cacharle.xyz> | 2020-08-02 11:05:33 +0200 |
|---|---|---|
| committer | Charles Cabergs <me@cacharle.xyz> | 2020-08-02 11:05:33 +0200 |
| commit | 5d2f925b20ceaea4122c59d2d2c4e7d4ae991fde (patch) | |
| tree | 80911dc3c32e9f230750e7e1042d413dfb6efab2 /src/dstr/ft_dstrnew.c | |
| parent | ee32953ea79616e72f5428cdf40c834714a891c9 (diff) | |
| parent | b96b82194ccad2cddbb46b77aa1962a57c47ff44 (diff) | |
| download | libft-5d2f925b20ceaea4122c59d2d2c4e7d4ae991fde.tar.gz libft-5d2f925b20ceaea4122c59d2d2c4e7d4ae991fde.tar.bz2 libft-5d2f925b20ceaea4122c59d2d2c4e7d4ae991fde.zip | |
Merge branch 'master' into ft_ssl
Diffstat (limited to 'src/dstr/ft_dstrnew.c')
| -rw-r--r-- | src/dstr/ft_dstrnew.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/dstr/ft_dstrnew.c b/src/dstr/ft_dstrnew.c new file mode 100644 index 0000000..c280dd1 --- /dev/null +++ b/src/dstr/ft_dstrnew.c @@ -0,0 +1,36 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_dstrnew.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/04/03 13:54:52 by charles #+# #+# */ +/* Updated: 2020/05/09 12:57:17 by charles ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft_dstr.h" + +/* +** \brief Create a new dynamic string +** \param from Static string to create the dynamic one from +** (will be duplicated) +** \return Created dynamic string or NULL on malloc error +*/ + +t_ftdstr *ft_dstrnew(char *from) +{ + t_ftdstr *dstr; + + dstr = NULL; + if ((dstr = (t_ftdstr*)malloc(sizeof(t_ftdstr))) == NULL || + (dstr->str = ft_strdup(from)) == NULL) + { + free(dstr); + return (NULL); + } + dstr->length = ft_strlen(from); + dstr->capacity = dstr->length + 1; + return (dstr); +} |
