data_structures
ds_strdup.c
Go to the documentation of this file.
1 /* ************************************************************************** */
3 /* */
4 /* ::: :::::::: */
5 /* ds_strdup.c :+: :+: :+: */
6 /* +:+ +:+ +:+ */
7 /* By: unite <marvin@42.fr> +#+ +:+ +#+ */
8 /* +#+#+#+#+#+ +#+ */
9 /* Created: 2019/09/04 22:50:26 by unite #+# #+# */
10 /* Updated: 2020/09/07 22:49:50 by unite ### ########.fr */
11 /* */
12 /* ************************************************************************** */
13 
14 #include "utils.h"
15 
20 char *ds_strdup(const char *s1)
21 {
22  size_t i;
23  char *cpy;
24 
25  cpy = ds_xcalloc(sizeof(char), ds_strlen(s1) + 1);
26  i = 0;
27  while (s1[i])
28  {
29  cpy[i] = s1[i];
30  i++;
31  }
32  cpy[i] = 0;
33  return (cpy);
34 }
ds_strlen
size_t ds_strlen(const char *s)
Replicates behaviour of strlen from libc.
Definition: ds_strlen.c:20
ds_xcalloc
void * ds_xcalloc(size_t count, size_t size)
Replicates behaviour of calloc from libc, but fails on memory allocation errors.
Definition: ds_xcalloc.c:22
utils.h
ds_strdup
char * ds_strdup(const char *s1)
Replicates behaviour of strdup from libc.
Definition: ds_strdup.c:20