电子说
VxWorks里怎样load一个文件到内存? 这个文件可以是在SD、USB、ATA这类的存储设备,也可以通过ftp网络下载;
下面是相关的实现代码,分享给大家:
STATUS ldToMem
(
char * fileName
)
{
UINT8 * pData;
FILE * fp;
UINT32 FileSize;
if (NULL == (fp = fopen(fileName,"rb")))
{
printf("open file failure\\n");
return ERROR;
}
#if FALSE
pfile = fopen("/sd0:0/fileName","rb");
#endif
fseek (fp, 0, SEEK_END);
FileSize = (UINT32) ftell (fp);
fseek (fp, 0, SEEK_SET);
if ((pData = malloc(FileSize)) == NULL)
{
printf("malloc failure\\n");
return ERROR;
}
if (fread (pData, 1, FileSize, fp) != FileSize)
{
printf("malloc failure\\n");
free(pData);
return ERROR;
}
printf("ldToMem OK pointer @ 0xx FileSize %d\\n",pData, FileSize);
}
全部0条评论
快来发表一下你的评论吧 !