/
Sapphire/bin/
Sapphire/db/
Sapphire/db/OLC_rooms/
Sapphire/db/abi/
Sapphire/db/em_src/
Sapphire/db/helps/
Sapphire/db/helps/emman/ifunc/
Sapphire/db/npcs/Tatt/
Sapphire/db/objects/Tatt/
Sapphire/db/q_data/
Sapphire/db/rooms/Tatt/
Sapphire/doc/
Sapphire/doc/em/
Sapphire/etc/
Sapphire/src/abic/
Sapphire/src/areacon/
Sapphire/src/client/
Sapphire/src/embc/
Sapphire/src/emi/
Sapphire/src/emi/test/
Sapphire/src/include/
Sapphire/src/sapphire/em/
Sapphire/src/tcon/
/*
 * Copyright (C) 1995-1997 Christopher D. Granz
 *
 * This header may not be removed.
 *
 * Refer to the file "License" included in this package for further
 * information and before using any of the following.
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#include "embc.h"


/*
 * Functions
 */

/*
 * Allocates some memory and checks for failure.
 */
void *alloc_mem( register size_t rsMem )
{
    register void *pMem;

    if ( ( pMem = calloc( 1, rsMem ) ) == NULL )
        fatal( "Compiler: "
          "Cannot allocate %ld bytes of memory.", (long) rsMem );

    return ( pMem );
}


/*
 * Reallocate some memory and check for failure.
 */
void *realloc_mem( register void *pMem, register size_t rsMem )
{
    if ( ( pMem = realloc( pMem, rsMem ) ) == NULL )
        fatal( "Compiler: "
          "Cannot reallocate %ld bytes of memory.", (long) rsMem );

    return ( pMem );
}


/*
 * Free some memory and set the pointer to NULL.
 */
void free_mem( register void **ppMem )
{
    if ( ppMem != NULL && *ppMem != NULL )
    {
        free( *ppMem );
        *ppMem = NULL;
    }
}


/*
 * Initialize some memory.
 */
void zero_out( register void *pMem, register size_t rsMem )
{
    register char *pCMem  = (char *) pMem;
    register size_t rs    = 0;

    while ( rs < rsMem )
    {
        pCMem[rs]         = 0;
        rs++;
    }
}


/*
 * Duplicates a string in memory.
 */
char *str_dup( register char *pStr )
{
    register int riLen;

    if ( pStr == NULL || pStr[0] == '\0' )
        return ( "" );

    riLen     = strlen( pStr );

    if ( riLen >= MAX_STRING )
        riLen = ( MAX_STRING - 1 );

    return ( strncpy( alloc_mem( riLen + 1 ), pStr, riLen ) );
}


/*
 * End of memory.c
 */