예제 #1
0
int VSIFEofL( VSILFILE * fp )

{
    VSIVirtualHandle *poFileHandle = (VSIVirtualHandle *) fp;
    
    return poFileHandle->Eof();
}
예제 #2
0
int VSIFEofL( VSILFILE * fp )

{
    VSIVirtualHandle *poFileHandle = reinterpret_cast<VSIVirtualHandle *>( fp );

    return poFileHandle->Eof();
}
예제 #3
0
int VSIStdoutRedirectHandle::Eof()

{
    return poHandle->Eof();
}
size_t VSIBufferedReaderHandle::Read( void *pBuffer, size_t nSize, size_t nMemb )
{
    const size_t nTotalToRead = nSize * nMemb;
    //CPLDebug( "BUFFERED", "Read(%d)", (int)nTotalToRead);

    if (nSize == 0)
        return 0;

    if (nBufferSize != 0 &&
            nCurOffset >= nBufferOffset && nCurOffset <= nBufferOffset + nBufferSize)
    {
        /* We try to read from an offset located within the buffer */
        const int nReadInBuffer = (int) MIN(nTotalToRead, nBufferOffset + nBufferSize - nCurOffset);
        memcpy(pBuffer, pabyBuffer + nCurOffset - nBufferOffset, nReadInBuffer);
        const int nToReadInFile = nTotalToRead - nReadInBuffer;
        if (nToReadInFile > 0)
        {
            /* The beginning of the the data to read is located in the buffer */
            /* but the end must be read from the file */
            if (bNeedBaseHandleSeek)
                poBaseHandle->Seek(nBufferOffset + nBufferSize, SEEK_SET);
            bNeedBaseHandleSeek = FALSE;
            //CPLAssert(poBaseHandle->Tell() == nBufferOffset + nBufferSize);

            const int nReadInFile = poBaseHandle->Read((GByte*)pBuffer + nReadInBuffer, 1, nToReadInFile);
            const int nRead = nReadInBuffer + nReadInFile;

            nBufferSize = MIN(nRead, MAX_BUFFER_SIZE);
            nBufferOffset = nCurOffset + nRead - nBufferSize;
            memcpy(pabyBuffer, (GByte*)pBuffer + nRead - nBufferSize, nBufferSize);

            nCurOffset += nRead;
            //CPLAssert(poBaseHandle->Tell() == nBufferOffset + nBufferSize);
            //CPLAssert(poBaseHandle->Tell() == nCurOffset);

            bEOF = poBaseHandle->Eof();

            return nRead / nSize;
        }
        else
        {
            /* The data to read is completely located within the buffer */
            nCurOffset += nTotalToRead;
            return nTotalToRead / nSize;
        }
    }
    else
    {
        /* We try either to read before or after the buffer, so a seek is necessary */
        poBaseHandle->Seek(nCurOffset, SEEK_SET);
        bNeedBaseHandleSeek = FALSE;
        const int nReadInFile = poBaseHandle->Read(pBuffer, 1, nTotalToRead);
        nBufferSize = MIN(nReadInFile, MAX_BUFFER_SIZE);
        nBufferOffset = nCurOffset + nReadInFile - nBufferSize;
        memcpy(pabyBuffer, (GByte*)pBuffer + nReadInFile - nBufferSize, nBufferSize);

        nCurOffset += nReadInFile;
        //CPLAssert(poBaseHandle->Tell() == nBufferOffset + nBufferSize);
        //CPLAssert(poBaseHandle->Tell() == nCurOffset);

        bEOF = poBaseHandle->Eof();

        return nReadInFile / nSize;
    }

}