]>
git.proxmox.com Git - wasi-libc.git/blob - libc-top-half/musl/src/malloc/calloc.c
7 static size_t mal0_clear(char *p
, size_t n
)
9 const size_t pagesz
= 4096; /* arbitrary */
10 if (n
< pagesz
) return n
;
12 typedef uint64_t __attribute__((__may_alias__
)) T
;
14 typedef unsigned char T
;
17 size_t i
= (uintptr_t)pp
& (pagesz
- 1);
19 pp
= memset(pp
- i
, 0, i
);
20 if (pp
- p
< pagesz
) return pp
- p
;
21 for (i
= pagesz
; i
; i
-= 2*sizeof(T
), pp
-= 2*sizeof(T
))
22 if (((T
*)pp
)[-1] | ((T
*)pp
)[-2])
27 static int allzerop(void *p
)
31 weak_alias(allzerop
, __malloc_allzerop
);
33 void *calloc(size_t m
, size_t n
)
35 if (n
&& m
> (size_t)-1/n
) {
41 if (!p
|| (!__malloc_replaced
&& __malloc_allzerop(p
)))
44 return memset(p
, 0, n
);