📄 flsysvxw.c
字号:
* mutex : Pointer to mutex *
* *
* Returns: *
* *
* always flOK *
* *
* ---------------------------------------------------------------------- */
FLStatus flCreateMutex ( FLMutex * mutex )
{
return flOK;
}
/* ---------------------------------------------------------------------- *
* *
* f l T a k e M u t e x *
* *
* Try to take mutex, if free. *
* *
* Parameters: *
* *
* mutex : Pointer to mutex *
* *
* Returns: *
* *
* always TRUE *
* *
* ---------------------------------------------------------------------- */
int flTakeMutex ( FLMutex * mutex )
{
return TRUE;
}
/* ---------------------------------------------------------------------- *
* *
* f l F r e e M u t e x *
* *
* Free mutex. *
* *
* Parameters: *
* *
* mutex : Pointer to mutex *
* *
* ---------------------------------------------------------------------- */
void flFreeMutex ( FLMutex * mutex )
{}
#ifdef EXIT
/* ---------------------------------------------------------------------- *
* *
* f l D e l e t e M u t e x *
* *
* Creates or initializes a mutex *
* *
* Parameters: *
* *
* mutex : Pointer to mutex *
* *
* ---------------------------------------------------------------------- */
void flDeleteMutex ( FLMutex * mutex )
{}
#endif /* EXIT */
/* ---------------------------------------------------------------------- *
* *
* t f f s S a v e M s g *
* *
* Append the message to the Debug Log. The message is assumed to *
* be shorter then 80 characters. If the Debug Log has not been created *
* yet, this routine creates and clears it. The size of the Debug Log is *
* detemined by the driver configuration variable fl_useDebug *
* (i.e. fl_useDebug == 3 means 3KB Debug Log). *
* *
* Parameters: *
* *
* msg : message to log *
* *
* ---------------------------------------------------------------------- */
void tffsSaveMsg ( char * msg )
{
register int i;
if (fl_useDebug) {
/* if debug log hasn't been created yet, create it know */
if (dbgLog == NULL) {
dbgLog = FL_MALLOC( fl_useDebug * 1024 );
if (dbgLog == NULL)
return;
dbgCurrent = dbgLog;
/* clear newly created log */
memset( (void *)dbgLog, 0, (fl_useDebug * 1024) );
}
/* append the message to log (if there is room for it) */
if (dbgCurrent - dbgLog < ((fl_useDebug * 1024) - 80)) {
/* don't want to use strcpy() */
for (i = 0; i < 80; i++, msg++) {
*dbgCurrent++ = *msg;
if (*msg == '\0')
break;
}
}
}
}
/* ---------------------------------------------------------------------- *
* *
* t f f s V i e w D e b u g L o g *
* *
* Returns a pointer to the Debug Log (NULL if fl_useDebug is zero). *
* *
* Returns: *
* *
* pointer to the beginning of debug log *
* *
* ---------------------------------------------------------------------- */
char * tffsViewDebugLog ( void )
{
return dbgLog;
}
/* ---------------------------------------------------------------------- *
* *
* f l m a l l o c *
* *
* Wrapper for ANSI C routine malloc(). Used to catch heap corruption. *
* *
* ---------------------------------------------------------------------- */
void * flmalloc ( size_t nBytes )
{
#ifdef FL_SYS_MEM_CORRUPTION
char * p;
p = malloc( sizeof(int) + FL_SYS_SENTINEL_STR_LEN + nBytes + FL_SYS_SENTINEL_STR_LEN);
if (p != NULL) {
/* record number of bytes allocated */
*((int *)p) = nBytes;
/* start sentinel */
memcpy( p + sizeof(int), sentinelStr, FL_SYS_SENTINEL_STR_LEN );
/* end sentinel */
memcpy( p + sizeof(int) + FL_SYS_SENTINEL_STR_LEN + nBytes,
sentinelStr, FL_SYS_SENTINEL_STR_LEN );
p += (sizeof(int) + FL_SYS_SENTINEL_STR_LEN);
}
printf ("malloc() allocated %d bytes at address 0x%lx\n", (int)nBytes, (long)p);
return p;
#else
return malloc (nBytes);
#endif /* FL_SYS_MEM_CORRUPTION */
}
/* ---------------------------------------------------------------------- *
* *
* f l f r e e *
* *
* Wrapper for ANSI C routine free(). Used to catch heap corruption. *
* *
* ---------------------------------------------------------------------- */
void flfree ( void * p )
{
#ifdef FL_SYS_MEM_CORRUPTION
int nBytes;
char * pp;
/* the beginning of allocated block */
pp = (char *)p - (sizeof(int) + FL_SYS_SENTINEL_STR_LEN);
/* number of bytes that was allocated */
nBytes = *((int *) pp);
printf ("freeing memory, %d bytes at 0x%lx\n", nBytes, (long)p);
/* is start sentinel ok ? */
if( memcmp(pp + sizeof(int), sentinelStr, FL_SYS_SENTINEL_STR_LEN) != 0)
printf ("Error, memory corruption detected !\n");
/* is end sentinel ok ? */
if( memcmp((char *)p + nBytes, sentinelStr, FL_SYS_SENTINEL_STR_LEN) != 0)
printf ("Error, memory corruption detected !\n");
/* trash start sentinel, so we know that region was freed */
memset (pp + sizeof(int), 0, FL_SYS_SENTINEL_STR_LEN);
/* free memory */
free (pp);
#else
free (p);
#endif /* FL_SYS_MEM_CORRUPTION */
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -