summaryrefslogtreecommitdiff
path: root/src/stdlib/calloc.c
blob: aeed4aef90faf6e13e096428c11eb179b46cb5e5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <stdlib.h>
#include "string.h"

/** allocate and initialize memory **/

void * calloc(size_t nmemb, size_t size)
{
	void *p = NULL;

	if (nmemb == 0 || size == 0) {
		return NULL;
	}

	p = realloc(NULL, size * nmemb);
	if (p != NULL) {
		memset(p, 0, size * nmemb);
	}

	return p;
}

/***
allocates an array of ARGUMENT(nmemb) elements, each of which
are ARGUMENT(size) bytes, and sets all their bits to 0.
***/

/*
UNSPECIFIED(The order and contiguity of space allocated by success calls)
IMPLEMENTATION(What is returned if ARGUMENT(nmemb) or ARGUMENT(size) is 0)
RETURN_FAILURE(CONSTANT(NULL))
RETURN_SUCCESS(a pointer to the newly allocated memory)
STDC(1)
*/