summaryrefslogtreecommitdiffstats
path: root/private/crt32/winheap/calloc.c
blob: ad93d8c55135c971567c7f1c84091fbc2f5e7b73 (plain) (blame)
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/***
*calloc.c - Win32 calloc heap routines
*
*	Copyright (c) 1991-1992, Microsoft Corporation.  All rights reserved.
*
*Purpose:
*
*Revision History:
*	01-10-92  JCR	Module created.
*	02-04-92  GJF	Replaced windows.h with oscalls.h.
*	05-06-92  DJM	POSIX support.
*	06-15-92  KRS	Enable C++ support.
*	09-09-92  SRW	_POSIX_ not even close.
*	09-23-92  SRW	Change winheap code to call NT directly always
*	10-28-92  SRW	Change winheap code to call Heap????Ex calls
*	11-05-92  SKS	Change name of variable "CrtHeap" to "_crtheap"
*	11-07-92  SRW   _NTIDW340 replaced by linkopts\betacmp.c
*	11-16-92  SRW   Heap???Ex functions renamed to Heap???
*
*******************************************************************************/

#include <malloc.h>
#include <winheap.h>
#include <os2dll.h>
#include <oscalls.h>

#ifndef _POSIX_
#include <new.h>
extern _PNH _pnhHeap;
#endif

/***
*void *calloc(size_t num, size_t size) - allocate storage for an array from
*	the heap
*
*Purpose:
*	Allocate a block of memory from heap big enough for an array of num
*	elements of size bytes each, initialize all bytes in the block to 0
*	and return a pointer to it.
*
*Entry:
*	size_t num	- number of elements in the array
*	size_t size	- size of each element
*
*Exit:
*	Success:  void pointer to allocated block block
*	Failure:  NULL
*
*Uses:
*
*Exceptions:
*
*******************************************************************************/

void * _CALLTYPE1 calloc ( num, size )
size_t num;
size_t size;

{
    HANDLE h;
    size_t n;

    if (!(n = num * size)) n = 1;

#ifndef _POSIX_
    for (;;) {
#endif  /* ndef _POSIX_ */

        h = HeapAlloc(_crtheap,
                        HEAP_ZERO_MEMORY,
                        n
                       );
#ifndef _POSIX_
	if ((h != 0) || (_pnhHeap == NULL) || (*_pnhHeap)(n) == 0)
#endif  /* ndef _POSIX_ */
	    return((void *)h);

#ifndef _POSIX_
        }
#endif  /* ndef _POSIX_ */
}