本文整理汇总了C++中QFile::unmap方法的典型用法代码示例。如果您正苦于以下问题:C++ QFile::unmap方法的具体用法?C++ QFile::unmap怎么用?C++ QFile::unmap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QFile
的用法示例。
在下文中一共展示了QFile::unmap方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: findEnd
uint JsonEngine::findEnd(QFile &file)
{
int len = file.size();
QByteArray data;
uchar *fmap = file.map(0, file.size());
if(!fmap)
{
data = file.readAll();
fmap = (uchar *)data.constData();
}
uint end = file.size();
const uchar *s = K8JSON::skipBlanks(fmap, &len);
uchar qch = *s;
if(!s || (qch != '[' && qch != '{'))
{
if(data.isEmpty())
file.unmap(fmap);
return end;
}
qch = (qch == '{' ? '}' : ']');
s++;
len--;
bool first = true;
while(s)
{
s = K8JSON::skipBlanks(s, &len);
if(len < 2 || (s && *s == qch))
{
if(*(s-1) == '\n')
s--;
end = (uint)(s - fmap);
break;
}
if(!s)
break;
if((!first && *s != ',') || (first && *s == ','))
break;
first = false;
if(*s == ',')
{
s++;
len--;
}
if(!(s = K8JSON::skipRec(s, &len)))
break;
}
if(data.isEmpty())
file.unmap(fmap);
return end;
}
示例2: hashFile
QByteArray Scanner::hashFile(QFile &f)
{
uchar *map;
QCryptographicHash hasher(QCryptographicHash::Sha1);
hasher.reset();
/* Try map first */
map = f.map( 0, f.size() );
if (NULL==map) {
/* no mmap, read in chunks */
uchar buffer[512];
qint64 r;
do {
r = f.read((char*)buffer,sizeof(buffer));
if (r<0){
throw 1;
}
if (r<=0)
break;
hasher.addData( (const char*)buffer, r);
} while (r>0);
} else {
hasher.addData((const char*)map,f.size());
f.unmap(map);
}
return hasher.result();
}
示例3: qWarning
FixFile::~FixFile()
{
// if the file was read into _data, it will be deleted automatically
if (_used_mmap && _file) {
if (0) qDebug("Unmapping '%s'", qPrintable( _filename ));
#if QT_VERSION >= 0x040400
QFile* mappableDevice = dynamic_cast<QFile*>(_file);
Q_ASSERT(mappableDevice);
if (!mappableDevice->unmap( (uchar*) _base ))
qWarning( "munmap: %s", strerror( errno ) );
#endif
}
}
示例4: QByteArray
QByteArray QCOMM::md5(QFile &file)
{
unsigned char *buf;
bool isopen;
if(!file.exists())
return QByteArray();
if(file.size()==0)
return QByteArray();
if(file.isOpen())
isopen = TRUE;
if(isopen&&(!file.open(QIODevice::ReadOnly)))
return QByteArray();
buf = file.map(0,file.size());
if(isopen)
file.close();
if(0==buf)
return QByteArray();
QByteArray data = QByteArray::fromRawData((char*)buf,file.size());
QByteArray md5 = QCryptographicHash::hash (data, QCryptographicHash::Md5);
file.unmap(buf);
return md5;
}