在dos下写程序,用的是borland c++ 4.5,读取大于64K文件时出现错误,相当的郁闷。谁能救救我?
问题的表现:程序完了以后,buf中只有文件的最后一小部分,长度大概就是len / readLen那么长,前边读取的部分应该是被覆盖了。
问题应该就出在memcpy上,可能是它不支持远指针(far *),但是我不知道应该用什么函数来替换它。
也可能是工程的内存模式的问题,我用的是huge模式,这里 是第二个问题:为什么我用large模式时,<iostream.h>中 的函数都会在build的时候出现link error:undefined symbol错误?
可怜可怜我吧!调试了很多天啦!
typedef unsigned char * puchar ;
typedef unsigned char _FAR * fpuchar ;
unsigned long mread(int fHandle , fpuchar buf , unsigned long len)
{
unsigned int readLen = UINT_MAX - 1 ;
int count = len / readLen ;
int lastRead = len % readLen ;
unsigned long pos = 0 ;
unsigned char * catche = new unsigned char[UINT_MAX - 1] ;
for(int i = 0 ; i <= count ; i ++)
{
if(i == count) readLen = lastRead ;
try
{
read(fHandle , catche , readLen) ;
memcpy(buf + pos , catche , readLen) ;
}
catch(...)
{
return 0 ;
}
pos += readLen ;
}
return pos ;
}