📄 plxmms_util.c
字号:
/***************************************************************************
*
* Pollex Mobile Platform
*
* Copyright (c) 2004 by Pollex Mobile Software Co., Ltd.
* All Rights Reserved
*
* Module :
*
* Purpose :
*
\**************************************************************************/
#include "PlxConfig.h"
#if defined(PROJECT_BRANCH_06A)
#define __NEWSIMULATOR
#include "FileSystemDef.h"
#undef __NEWSIMULATOR
#endif // PROJECT_BRANCH_06A
#include "PlxMms_Util.h"
#include "Fs_type.h"
#include "Fs_func.h"
#include "..\public\PlxAppMem.h"
#if defined(MMS_SELECTSTOREPATH) || defined(MMS_SAVEONCARD)
extern char g_plug_path[PLXMMS_PATH_MAXLEN];
#endif
#ifdef MMS_SELECTSTOREPATH //plug card path
extern char* g_cur_path;
#endif
extern U16 AnsiiToUnicodeString(S8 *pOutBuffer, S8 *pInBuffer );
#ifdef MMS_CHECKMEM
//typedef unsigned short WCHAR;
typedef struct tagMemInfoNode
{
void* p;
char file[256];
int line;
struct tagMemInfoNode* next;
}MemInfoNode;
static MemInfoNode* g_meminfo_head = NULL;
static int g_meminfo_count = 0;
static void AddInfo(void* p, char* file, int line)
{
MemInfoNode* node = NULL;
if(!p || !file)
return;
#ifdef MMI_ON_WIN32
node = (MemInfoNode*)malloc(sizeof(MemInfoNode));
#else
node = (MemInfoNode*)PlxAppMalloc(sizeof(MemInfoNode));
#endif
if(!node)
return;
node->p = p;
MMS_Strcpy(node->file, file);
node->line = line;
node->next = NULL;
node->next = g_meminfo_head;
g_meminfo_head = node;
g_meminfo_count++;
}
static void DelInfo(void* p)
{
MemInfoNode* node = NULL;
MemInfoNode* prev = NULL;
if(!g_meminfo_head)
return;
if(g_meminfo_head->p == p)
{
node = g_meminfo_head;
g_meminfo_head = node->next;
#ifdef MMI_ON_WIN32
free((void*)node);
#else
PlxAppFree((void*)node);
#endif
g_meminfo_count--;
return;
}
prev = g_meminfo_head;
node = g_meminfo_head->next;
while(node)
{
if(node->p == p)
{
prev->next = node->next;
#ifdef MMI_ON_WIN32
free((void*)node);
#else
PlxAppFree((void*)node);
#endif
g_meminfo_count--;
break;
}
node = node->next;
prev = prev->next;
}
}
void ResetInfo()
{
MemInfoNode* node = NULL;
if(!g_meminfo_head)
return;
node = g_meminfo_head;
while(node)
{
g_meminfo_head = g_meminfo_head->next;
#ifdef MMI_ON_WIN32
free((void*)node);
#else
PlxAppFree((void*)node);
#endif
node = g_meminfo_head;
}
g_meminfo_count = 0;
}
#endif //MMS_CHECKMEM
/***************************************************************************
* Function MMS_Malloc
* Purpose
* Params
* Return
* Remarks
\**************************************************************************/
#ifdef MMS_CHECKMEM
void* MMS_MemMalloc(size_t size, char* file, int line)
#else
void* MMS_Malloc(size_t size)
#endif
{
#ifdef MMS_CHECKMEM
void* p = NULL;
#ifdef MMI_ON_WIN32
p = malloc(size);
#else
p = PlxAppMalloc(size);
#endif
if(!p)
return NULL;
AddInfo(p, file, line);
return p;
#else //MMS_CHECKMEM
#ifdef MMI_ON_WIN32
return malloc(size);
#else
return PlxAppMalloc(size);
#endif
#endif //MMS_CHECKMEM
}
/***************************************************************************
* Function MMS_Free
* Purpose
* Params
* Return
* Remarks
\**************************************************************************/
#ifdef MMS_CHECKMEM
void MMS_MemFree(void* p)
#else
void MMS_Free(void* p)
#endif
{
#ifdef MMI_ON_WIN32
free(p);
#else
PlxAppFree(p);
#endif
#ifdef MMS_CHECKMEM
DelInfo(p);
#endif
}
/***************************************************************************
* Function MMS_Realloc
* Purpose
* Params
* Return
* Remarks
\**************************************************************************/
void* MMS_Realloc(void* p, size_t size)
{
#ifdef MMI_ON_WIN32
return realloc(p, size);
#else
return PlxAppRealloc(p, size);
#endif
}
/***************************************************************************
* Function MMS_Memset
* Purpose
* Params
* Return
* Remarks
\**************************************************************************/
void * MMS_Memset(void *m, int c, unsigned int n)
{
#ifdef MMI_ON_WIN32
return memset(m, c, n);
#endif
return plx_memset(m, c, n);
}
/***************************************************************************
* Function MMS_Memcpy
* Purpose
* Params
* Return
* Remarks
\**************************************************************************/
void* MMS_Memcpy(void *dst0, const void *src0, unsigned int len0)
{
#ifdef MMI_ON_WIN32
return memcpy(dst0, src0, len0);
#else
return plx_memcpy(dst0, src0, len0);
#endif
}
/***************************************************************************
* Function MMS_Memcmp
* Purpose
* Params
* Return
* Remarks
\**************************************************************************/
int MMS_Memcmp(const void *m1, const void *m2, unsigned int n)
{
return plx_memcmp(m1, m2, n);
}
/***************************************************************************
* Function MMS_Memmove
* Purpose
* Params
* Return
* Remarks
\**************************************************************************/
void* MMS_Memmove(void *dst_void, const void *src_void, unsigned int length)
{
#ifdef MMI_ON_WIN32
return memmove(dst_void, src_void, length);
#else
return plx_memmove(dst_void, src_void, length);
#endif
}
/***************************************************************************
* Function MMS_Strncpy
* Purpose
* Params
* Return
* Remarks
\**************************************************************************/
void * MMS_Strncpy(char *dst0, const char *src0, unsigned int count)
{
#ifdef MMI_ON_WIN32
return strncpy(dst0, src0, count);
#else
return plx_strncpy(dst0, src0, count);
#endif
}
/***************************************************************************
* Function MMS_Strcpy
* Purpose
* Params
* Return
* Remarks
\**************************************************************************/
char * MMS_Strcpy(char *dst0, const char *src0)
{
#ifdef MMI_ON_WIN32
return strcpy(dst0, src0);
#else
return plx_strcpy(dst0, src0);
#endif
}
/***************************************************************************
* Function MMS_Strstr
* Purpose
* Params
* Return
* Remarks
\**************************************************************************/
char* MMS_Strstr(const char* str, const char* strCharSet)
{
#ifdef MMI_ON_WIN32
return strstr(str, strCharSet);
#else
return plx_strstr(str, strCharSet);
#endif
}
/***************************************************************************
* Function MMS_Strlen
* Purpose
* Params
* Return
* Remarks
\**************************************************************************/
unsigned int MMS_Strlen(const char* str)
{
#ifdef MMI_ON_WIN32
return strlen(str);
#else
return plx_strlen(str);
#endif
}
/***************************************************************************
* Function MMS_Strcat
* Purpose
* Params
* Return
* Remarks
\**************************************************************************/
char* MMS_Strcat(char* dst, const char* src)
{
#ifdef MMI_ON_WIN32
return strcat(dst, src);
#else
return plx_strcat(dst, src);
#endif
}
/***************************************************************************
* Function MMS_Strncat
* Purpose
* Params
* Return
* Remarks
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -