/* ===========================================================================
*
*                            PUBLIC DOMAIN NOTICE
*               National Center for Biotechnology Information
*
*  This software/database is a "United States Government Work" under the
*  terms of the United States Copyright Act.  It was written as part of
*  the author's official duties as a United States Government employee and
*  thus cannot be copyrighted.  This software/database is freely available
*  to the public for use. The National Library of Medicine and the U.S.
*  Government have not placed any restriction on its use or reproduction.
*
*  Although all reasonable efforts have been taken to ensure the accuracy
*  and reliability of the software and data, the NLM and the U.S.
*  Government do not and cannot warrant the performance or results that
*  may be obtained by using this software or data. The NLM and the U.S.
*  Government disclaim all warranties, express or implied, including
*  warranties of performance, merchantability or fitness for any particular
*  purpose.
*
*  Please cite the author in any work or product based on this material.
*
* ===========================================================================*/
#include <ncbi.h>
#include <stdarg.h>
#include <blast/blast.h>

static Nlm_VoidPtr	LIBCALL local_malloc PROTO((size_t size));
static Nlm_VoidPtr	LIBCALL local_calloc PROTO((size_t size));
static Nlm_VoidPtr	LIBCALL local_realloc PROTO((Nlm_VoidPtr p, size_t newsize));
static void		LIBCALL local_free PROTO((Nlm_VoidPtr));

BLAST_Error
_blast_util_init(bcp)
	BLAST_ConfigPtr	bcp;
{
	bcp->calloc = local_calloc;
	bcp->malloc = local_malloc;
	bcp->realloc = local_realloc;
	bcp->free = local_free;
	return blast_errno = BLAST_ERR_NONE;
}

static Nlm_VoidPtr
local_malloc(size)
	size_t	size;
{
	return Nlm_Malloc(size);
}

static Nlm_VoidPtr
local_calloc(size)
	size_t	size;
{
	return Nlm_Calloc(size, 1);
}

static Nlm_VoidPtr
local_realloc(p, size)
	Nlm_VoidPtr	p;
	size_t	size;
{
	return Nlm_Realloc(p, size);
}

static void
local_free(p)
	Nlm_VoidPtr	p;
{
	(void) Nlm_Free(p);
}


Nlm_VoidPtr
BlastMalloc(size)
	size_t	size;
{
	Nlm_VoidPtr	vp;

	vp = (*blast_config->malloc)(size);
	if (vp == NULL)
		blast_errno = BLAST_ERR_MEM;
	return vp;
}

Nlm_VoidPtr
BlastCalloc(size)
	size_t	size;
{
	Nlm_VoidPtr	vp;

	vp = (*blast_config->calloc)(size);
	if (vp == NULL)
		blast_errno = BLAST_ERR_MEM;
	return vp;
}

Nlm_VoidPtr
BlastRealloc(p, size)
	Nlm_VoidPtr	p;
	size_t	size;
{
	Nlm_VoidPtr	vp;

	vp = (*blast_config->realloc)(p, size);
	if (vp == NULL)
		blast_errno = BLAST_ERR_MEM;
	return vp;
}

void
BlastFree(p)
	Nlm_VoidPtr	p;
{
	if (p != NULL)
		(*blast_config->free)(p);
}
