因此,该读取适用于Windows,但它不适用于Linux。在GDB中,ulTop变量显示为0,即使它应该是512(Constants :: INITIAL_READ_SIZE的值)。
std::basic_ifstream<unsigned char> file (szFileName, std::ios::in|std::ios::binary);
if (!file)
{
if (m_iDisplayType != ConsoleOutput::NO_DISPLAY)
{
std::cout << "There was a problem opening the file." << std::endl;
std::cerr << "Error: " << strerror(errno) << std::endl;
}
return false;
}
long lFileSize;
// Grab the file size
file.seekg( 0, std::ios::end );
lFileSize = file.tellg();
file.seekg( 0, std::ios::beg );
unsigned long ulTop = 0; // how much of the file is in the pszBuffer
// Do an initial read of the file, to get some data in our pszBuffer, ready for processing...
file.read( &m_szContents[ ulTop ], Constants::INITIAL_READ_SIZE );
ulTop += file.gcount();
memcpy(m_szPcapHeader, m_szContents, Constants::PCAP_HEADER_SIZE);
奇怪的是它打印出正确的文件大小,但是从file.gcount()增加后的ulTop是0 - 在Windows中它是正确的512.我真的无法弄清楚发生了什么。有什么想法吗?
由于
PS:m_szContents是无符号字符m_szContents [Constants :: LARGE_BUFFER_SIZE],ulTop是无符号长整数。