2010-05-06 00:08:41 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <malloc.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#define PIC_ERRSIZE 256
|
|
|
|
|
|
|
|
static unsigned long PIC_Sys_MEM_Allocated;
|
|
|
|
static unsigned long PIC_Sys_MEM_NbAllocs;
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void *Pic_malloc(unsigned long size)
|
|
|
|
{
|
|
|
|
void *mem;
|
|
|
|
mem=malloc(size);
|
|
|
|
if (mem)
|
|
|
|
{
|
|
|
|
PIC_Sys_MEM_Allocated+=size;
|
|
|
|
PIC_Sys_MEM_NbAllocs++;
|
|
|
|
}
|
|
|
|
return(mem);
|
|
|
|
}
|
|
|
|
// -----
|
|
|
|
void *Pic_calloc(unsigned long count, unsigned long size)
|
|
|
|
{
|
|
|
|
void *mem;
|
|
|
|
mem=calloc(count,size);
|
|
|
|
if (mem)
|
|
|
|
{
|
|
|
|
PIC_Sys_MEM_Allocated+=(size*count);
|
|
|
|
PIC_Sys_MEM_NbAllocs++;
|
|
|
|
}
|
|
|
|
return(mem);
|
|
|
|
}
|
|
|
|
// -----
|
|
|
|
void Pic_free(void *memblock)
|
|
|
|
{
|
|
|
|
unsigned long size;
|
2010-09-25 13:53:28 +00:00
|
|
|
size=(unsigned long)_msize(memblock);
|
2010-05-06 00:08:41 +00:00
|
|
|
PIC_Sys_MEM_Allocated-=size;
|
|
|
|
PIC_Sys_MEM_NbAllocs--;
|
|
|
|
free(memblock);
|
|
|
|
}
|
|
|
|
// -----
|
|
|
|
unsigned long Pic__msize(void *memblock)
|
|
|
|
{
|
2010-09-25 13:53:28 +00:00
|
|
|
return(unsigned long)(_msize(memblock));
|
2010-05-06 00:08:41 +00:00
|
|
|
}
|
|
|
|
// -----
|
|
|
|
unsigned long PIC_GetMemNbAllocs(void)
|
|
|
|
{
|
|
|
|
return(PIC_Sys_MEM_NbAllocs);
|
|
|
|
}
|
|
|
|
// -----
|
|
|
|
unsigned long PIC_GetMemAllocated(void)
|
|
|
|
{
|
|
|
|
return(PIC_Sys_MEM_Allocated);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
2010-09-25 13:53:28 +00:00
|
|
|
static char PIC_ErrorFlag;
|
|
|
|
static char PIC_ErrorString[PIC_ERRSIZE];
|
2010-05-06 00:08:41 +00:00
|
|
|
static unsigned char PIC_Sys_FnctActive=0;
|
|
|
|
static void (*PIC_Sys_Fnct)(void);
|
|
|
|
|
2010-09-25 13:53:28 +00:00
|
|
|
void Pic_SetError(const char *msg, ...)
|
2010-05-06 00:08:41 +00:00
|
|
|
{
|
2010-09-25 13:53:28 +00:00
|
|
|
char curerr[PIC_ERRSIZE],olderr[PIC_ERRSIZE];
|
2010-05-06 00:08:41 +00:00
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start(args,msg);
|
|
|
|
vsprintf(curerr,msg,args);
|
|
|
|
va_end(args);
|
|
|
|
if ( (strlen(curerr)+strlen(PIC_ErrorString))>PIC_ERRSIZE ) return;
|
|
|
|
|
|
|
|
if (PIC_ErrorFlag)
|
|
|
|
{
|
|
|
|
strcpy(olderr,PIC_ErrorString);
|
|
|
|
sprintf(PIC_ErrorString,"--- [PIC#%03d] :\n%s",PIC_ErrorFlag,curerr);
|
|
|
|
strcat(PIC_ErrorString,"\n");
|
|
|
|
strcat(PIC_ErrorString,olderr);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sprintf(PIC_ErrorString,"--- [PIC#%03d] :\n%s",PIC_ErrorFlag,curerr);
|
|
|
|
}
|
|
|
|
PIC_ErrorFlag++;
|
|
|
|
if (PIC_Sys_FnctActive) PIC_Sys_Fnct();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// -----
|
|
|
|
char* PIC_GetError(void)
|
|
|
|
{
|
|
|
|
return(PIC_ErrorString);
|
|
|
|
}
|
|
|
|
// -----
|
|
|
|
unsigned char PIC_Error(void)
|
|
|
|
{
|
|
|
|
return(PIC_ErrorFlag);
|
|
|
|
}
|
|
|
|
// -----
|
|
|
|
void PIC_ResetError(void)
|
|
|
|
{
|
|
|
|
strcpy(PIC_ErrorString,"");
|
|
|
|
PIC_ErrorFlag=0;
|
|
|
|
}
|
|
|
|
// -----
|
|
|
|
unsigned char PIC_OnErrorCall( void pFnct(void) )
|
|
|
|
{
|
|
|
|
if (pFnct != NULL)
|
|
|
|
{
|
|
|
|
PIC_Sys_Fnct=pFnct;
|
|
|
|
PIC_Sys_FnctActive=1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PIC_Sys_FnctActive=0;
|
|
|
|
}
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
|