X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flibpspp%2Fpool.c;h=c39852dcc7a2977becee7d8c0b970c11d52471d4;hb=c97f6581b874c6057dbd4d581552774a3ed56ac5;hp=141d8ab40323b94fea587ce801369bde6938b7aa;hpb=8cd2dcd874841a5a7a64a42f76ee9d1fae5718ad;p=pspp-builds.git diff --git a/src/libpspp/pool.c b/src/libpspp/pool.c index 141d8ab4..c39852dc 100644 --- a/src/libpspp/pool.c +++ b/src/libpspp/pool.c @@ -472,6 +472,34 @@ pool_nmalloc (struct pool *pool, size_t n, size_t s) return pool_malloc (pool, n * s); } +/* Allocates AMT bytes using malloc(), to be managed by POOL, + zeros the block, and returns a pointer to the beginning of the + block. + If POOL is a null pointer, then allocates a normal memory block + with xmalloc(). */ +void * +pool_zalloc (struct pool *pool, size_t amt) +{ + void *p = pool_malloc (pool, amt); + memset (p, 0, amt); + return p; +} + +/* Allocates and returns N elements of S bytes each, to be + managed by POOL, and zeros the block. + If POOL is a null pointer, then allocates a normal memory block + with malloc(). + N must be nonnegative, S must be positive. + Terminates the program if the memory cannot be obtained, + including the case where N * S overflows the range of size_t. */ +void * +pool_calloc (struct pool *pool, size_t n, size_t s) +{ + void *p = pool_nmalloc (pool, n, s); + memset (p, 0, n * s); + return p; +} + /* Changes the allocation size of the specified memory block P managed by POOL to AMT bytes and returns a pointer to the beginning of the block.