data_structures
ds_xcalloc.c
Go to the documentation of this file.
1 /* ************************************************************************** */
3 /* */
4 /* ::: :::::::: */
5 /* ds_calloc.c :+: :+: :+: */
6 /* +:+ +:+ +:+ */
7 /* By: unite <marvin@42.fr> +#+ +:+ +#+ */
8 /* +#+#+#+#+#+ +#+ */
9 /* Created: 2019/09/05 00:27:33 by unite #+# #+# */
10 /* Updated: 2020/09/07 21:41:56 by unite ### ########.fr */
11 /* */
12 /* ************************************************************************** */
13 
14 #include "utils.h"
15 #include <stdlib.h>
16 
22 void *ds_xcalloc(size_t count, size_t size)
23 {
24  void *mem;
25 
26  mem = malloc(count * size);
27  if (!mem && !size)
28  ds_exit();
29  ds_bzero(mem, count * size);
30  return (mem);
31 }
ds_bzero
void ds_bzero(void *s, size_t n)
Replicates behaviour of bzero from libc.
Definition: ds_bzero.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_exit
void ds_exit(void)
Print the error message, corresponding to errno, exit the process.
Definition: ds_exit.c:20