scot_exceptions.c 1.08 KB
#include <stdio.h>

#include <scot/scot_exceptions.h>
#include <scot/exception.h>
#include <scot/memory.h>
#include <scot_common.h>
#include <scot/scot_types.h>

const char *scot_err_msg[] = {
   N_("[SCOT]malloc failed"),
   N_("[SCOT]NULL pointer not allowed"),
   NULL
};


void *
exc_malloc (SIZE_T size)
{
   return exc_malloc_fl (size, __FILE__, __LINE__);
}

void *
exc_malloc_fl (SIZE_T size, const char *file, int line)
{
   void *a;

   bindtextdomain (PACKAGE, LOCALEDIR);
   a = SCOT_MEM_GET (size);

   if (a == NULL)
      THROW (exc_new (
               EXC_ERROR, 
               file, 
               line, 
               MALLOC_ERR, 
               D_(scot_err_msg [MALLOC_ERR])));

   return a;
}

void
check_null (const void *var)
{
   check_null_fl (var, __FILE__, __LINE__);
}

void
check_null_fl (const void *var, const char* file, int line)
{
   bindtextdomain (PACKAGE, LOCALEDIR);

   if (var == NULL)
      THROW (exc_new (
               EXC_ERROR, 
               file, 
               line, 
               NULL_PTR_ERR, 
               D_(scot_err_msg [NULL_PTR_ERR])));
}