Mercurial > dovecot > core-2.2
view src/lib/mempool-system.c @ 1741:9df02b1533b3 HEAD
Removed most of the license comments from src/lib/*.c. It's just fine to
keep them in a single COPYING.MIT file. Changed a few other comments as well.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Wed, 27 Aug 2003 00:18:16 +0300 |
parents | 826bed85c807 |
children | 2f3d906d99d8 |
line wrap: on
line source
/* Copyright (c) 2002-2003 Timo Sirainen */ /* @UNSAFE: whole file */ #include "lib.h" #include "mempool.h" #include <stdlib.h> static const char *pool_system_get_name(pool_t pool); static void pool_system_ref(pool_t pool); static void pool_system_unref(pool_t pool); static void *pool_system_malloc(pool_t pool, size_t size); static void pool_system_free(pool_t pool, void *mem); static void *pool_system_realloc(pool_t pool, void *mem, size_t old_size, size_t new_size); static void pool_system_clear(pool_t pool); static struct pool static_system_pool = { pool_system_get_name, pool_system_ref, pool_system_unref, pool_system_malloc, pool_system_free, pool_system_realloc, pool_system_clear, FALSE }; pool_t system_pool = &static_system_pool; static const char *pool_system_get_name(pool_t pool __attr_unused__) { return "system"; } static void pool_system_ref(pool_t pool __attr_unused__) { } static void pool_system_unref(pool_t pool __attr_unused__) { } static void *pool_system_malloc(pool_t pool __attr_unused__, size_t size) { void *mem; if (size == 0 || size > SSIZE_T_MAX) i_panic("Trying to allocate %"PRIuSIZE_T" bytes", size); mem = calloc(size, 1); if (mem == NULL) i_panic("pool_system_malloc(): Out of memory"); return mem; } static void pool_system_free(pool_t pool __attr_unused__, void *mem) { if (mem != NULL) free(mem); } static void *pool_system_realloc(pool_t pool __attr_unused__, void *mem, size_t old_size, size_t new_size) { if (new_size == 0 || new_size > SSIZE_T_MAX) i_panic("Trying to allocate %"PRIuSIZE_T" bytes", new_size); mem = realloc(mem, new_size); if (mem == NULL) i_panic("pool_system_realloc(): Out of memory"); if (old_size < new_size) { /* clear new data */ memset((char *) mem + old_size, 0, new_size - old_size); } return mem; } static void pool_system_clear(pool_t pool __attr_unused__) { i_panic("pool_system_clear() must not be called"); }