libc: move calloc() into its own compilation unit
move calloc() in its own compilation unit to avoid code duplication. also, calloc() is used rarely in plan9 programs.
This commit is contained in:
parent
bf9bada0c2
commit
5c1feb0ef0
4 changed files with 14 additions and 21 deletions
13
sys/src/libc/port/calloc.c
Normal file
13
sys/src/libc/port/calloc.c
Normal file
|
@ -0,0 +1,13 @@
|
|||
#include <u.h>
|
||||
#include <libc.h>
|
||||
|
||||
void*
|
||||
calloc(ulong n, ulong s)
|
||||
{
|
||||
void *v;
|
||||
if(n > 1 && ((ulong)-1)/n < s)
|
||||
return nil;
|
||||
if(v = mallocz(n*s, 1))
|
||||
setmalloctag(v, getcallerpc(&n));
|
||||
return v;
|
||||
}
|
|
@ -279,18 +279,6 @@ msize(void *v)
|
|||
return poolmsize(mainmem, (ulong*)v-Npadlong)-Npadlong*sizeof(ulong);
|
||||
}
|
||||
|
||||
void*
|
||||
calloc(ulong n, ulong s)
|
||||
{
|
||||
void *v;
|
||||
|
||||
if(n > 1 && ((ulong)-1)/n < s)
|
||||
return nil;
|
||||
if(v = mallocz(n*s, 1))
|
||||
setmalloctag(v, getcallerpc(&n));
|
||||
return v;
|
||||
}
|
||||
|
||||
void
|
||||
setmalloctag(void *v, uintptr pc)
|
||||
{
|
||||
|
|
|
@ -12,6 +12,7 @@ CFILES=\
|
|||
atof.c\
|
||||
atol.c\
|
||||
atoll.c\
|
||||
calloc.c\
|
||||
cistrcmp.c\
|
||||
cistrncmp.c\
|
||||
cistrstr.c\
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue