我在嘗試打開文件以二進制模式讀取時遇到問題。無法以二進制模式讀取文件中的數據,C語言
的代碼是這樣的:
PT_LONG LoadDataFromFile1(const char *pFileName,
unsigned char **ppBufer, PT_LONG *pLenData)
{
PT_LONG retVal = 0;
PT_DWORD fileLength = 0,len,i;
unsigned char *buff,fn[35];
unsigned char buff1[500];
FILE *fil = NULL;
fil = fopen(pFileName, "rb");
if (fil != NULL)
{
fseek(fil, 0, SEEK_END);
fileLength = ftell(fil);
if (fileLength > 0)
{
*ppBufer = (unsigned char *) malloc(fileLength);
*pLenData = (PT_DWORD) fileLength;
printf("\n\n test file length:%d\n\n",fileLength);
fseek(fil, 0, SEEK_SET);
fread(*ppBufer, 1, fileLength, fil);
}
else
{
retVal = -2;
}
fclose(fil);
}
else
{
retVal = -1;
}
return retVal;
}
這裏
如果pFileName=/mnt/jffs2/bir/1234.bir
它的正常工作。但是,如果pfilename=/mnt/jffs2/bir/11772213A7894568.bir
我無法讀取文件中的數據。它返回-1。
您確定有權限閱讀這兩個文件嗎? – Heisenbug