openbmc/build/tmp/deploy/sdk/witherspoon-2019-08-08/sysroots/armv6-openbmc-linux-gnueabi/usr/src/debug/rsyslog/8.1903.0-r0/rsyslog-8.1903.0/runtime/stream.c
static rsRetVal strmReadBuf(strm_t* pThis, int* padBytes)
{
    DEFiRet;
    int bRun;
    long iLenRead;
    size_t actualDataLen;
    size_t toRead;
    ssize_t bytesLeft;

    ISOBJ_TYPE_assert(pThis, strm);
    /* We need to try read at least twice because we may run into EOF and need
     * to switch files. */
    bRun = 1;
    while (bRun)
    {
        /* first check if we need to (re)open the file. We may have switched to
         * a new one in circular mode or it may have been rewritten (rotated) if
         * we monitor a file rgerhards, 2008-02-13
         */
        CHKiRet(strmOpenFile(pThis));
        if (pThis->cryprov == NULL)
        {
            toRead = pThis->sIOBufSize;
        }
        else
        {
            CHKiRet(pThis->cryprov->GetBytesLeftInBlock(pThis->cryprovFileData,
                                                        &bytesLeft));
            if (bytesLeft == -1 || bytesLeft > (ssize_t)pThis->sIOBufSize)
            {
                toRead = pThis->sIOBufSize;
            }
            else
            {
                toRead = (size_t)bytesLeft;
            }
        }
        if (pThis->bReopenOnTruncate)
        {
            rsRetVal localRet = checkTruncation(pThis);
            if (localRet == RS_RET_FILE_TRUNCATED)
            {
                continue;
            }
            CHKiRet(localRet);
        }
        iLenRead = read(pThis->fd, pThis->pIOBuf, toRead);
        DBGOPRINT((obj_t*)pThis, "file %d read %ld bytes\n", pThis->fd,
                  iLenRead);
        /* end crypto */
        if (iLenRead == 0)
        {
            CHKiRet(strmHandleEOF(pThis));
        }
        else if (iLenRead < 0)
            ABORT_FINALIZE(RS_RET_IO_ERROR);
        else
        { /* good read */
            /* here we place our crypto interface */
            if (pThis->cryprov != NULL)
            {
                actualDataLen = iLenRead;
                pThis->cryprov->Decrypt(pThis->cryprovFileData, pThis->pIOBuf,
                                        &actualDataLen);
                *padBytes = iLenRead - actualDataLen;
                iLenRead = actualDataLen;
                DBGOPRINT((obj_t*)pThis,
                          "encrypted file %d pad bytes %d, actual "
                          "data %ld\n",
                          pThis->fd, *padBytes, iLenRead);
            }
            else
            {
                *padBytes = 0;
            }
            pThis->iBufPtrMax = iLenRead;
            bRun = 0; /* exit loop */
        }
    }
    /* if we reach this point, we had a good read */
    pThis->iBufPtr = 0;

finalize_it:
    RETiRet;
}
/* read the next buffer from disk
 * rgerhards, 2008-02-13
 */
read the next buffer from disk
rgerhards, 2008-02-13
read the next buffer from disk rgerhards 2008 - 02 - 13
static rsRetVal strmReadBuf(strm_t* pThis, int* padBytes)
{
    DEFiRet;
    int bRun;
    long iLenRead;
    size_t actualDataLen;
    size_t toRead;
    ssize_t bytesLeft;
    ISOBJ_TYPE_assert(pThis, strm);
    bRun = 1;
    while (bRun)
    {
        CHKiRet(strmOpenFile(pThis));
        if (pThis->cryprov == NULL)
        {
            toRead = pThis->sIOBufSize;
        }
        else
        {
            CHKiRet(pThis->cryprov->GetBytesLeftInBlock(pThis->cryprovFileData,
                                                        &bytesLeft));
            if (bytesLeft == -1 || bytesLeft > (ssize_t)pThis->sIOBufSize)
            {
                toRead = pThis->sIOBufSize;
            }
            else
            {
                toRead = (size_t)bytesLeft;
            }
        }
        if (pThis->bReopenOnTruncate)
        {
            rsRetVal localRet = checkTruncation(pThis);
            if (localRet == RS_RET_FILE_TRUNCATED)
            {
                continue;
            }
            CHKiRet(localRet);
        }
        iLenRead = read(pThis->fd, pThis->pIOBuf, toRead);
        DBGOPRINT((obj_t*)pThis, "file %d read %ld bytes\n", pThis->fd,
                  iLenRead);
        if (iLenRead == 0)
        {
            CHKiRet(strmHandleEOF(pThis));
        }
        else if (iLenRead < 0)
            ABORT_FINALIZE(RS_RET_IO_ERROR);
        else
        { 
            if (pThis->cryprov != NULL)
            {
                actualDataLen = iLenRead;
                pThis->cryprov->Decrypt(pThis->cryprovFileData, pThis->pIOBuf,
                                        &actualDataLen);
                *padBytes = iLenRead - actualDataLen;
                iLenRead = actualDataLen;
                DBGOPRINT((obj_t*)pThis,
                          "encrypted file %d pad bytes %d, actual "
                          "data %ld\n",
                          pThis->fd, *padBytes, iLenRead);
            }
            else
            {
                *padBytes = 0;
            }
            pThis->iBufPtrMax = iLenRead;
            bRun = 0; 
        }
    }
    pThis->iBufPtr = 0;
finalize_it:
    RETiRet;
}
static rsRetVal strmReadBuf ( strm_t * pThis , int * padBytes ) { DEFiRet ; int bRun ; long iLenRead ; size_t actualDataLen ; size_t toRead ; ssize_t bytesLeft ; ISOBJ_TYPE_assert ( pThis , strm ) ; bRun = 1 ; while ( bRun ) { CHKiRet ( strmOpenFile ( pThis ) ) ; if ( pThis -> cryprov == NULL ) { toRead = pThis -> sIOBufSize ; } else { CHKiRet ( pThis -> cryprov -> GetBytesLeftInBlock ( pThis -> cryprovFileData , & bytesLeft ) ) ; if ( bytesLeft == -1 || bytesLeft > ( ssize_t ) pThis -> sIOBufSize ) { toRead = pThis -> sIOBufSize ; } else { toRead = ( size_t ) bytesLeft ; } } if ( pThis -> bReopenOnTruncate ) { rsRetVal localRet = checkTruncation ( pThis ) ; if ( localRet == RS_RET_FILE_TRUNCATED ) { continue ; } CHKiRet ( localRet ) ; } iLenRead = read ( pThis -> fd , pThis -> pIOBuf , toRead ) ; DBGOPRINT ( ( obj_t * ) pThis , " \n " , pThis -> fd , iLenRead ) ; if ( iLenRead == 0 ) { CHKiRet ( strmHandleEOF ( pThis ) ) ; } else if ( iLenRead < 0 ) ABORT_FINALIZE ( RS_RET_IO_ERROR ) ; else { if ( pThis -> cryprov != NULL ) { actualDataLen = iLenRead ; pThis -> cryprov -> Decrypt ( pThis -> cryprovFileData , pThis -> pIOBuf , & actualDataLen ) ; * padBytes = iLenRead - actualDataLen ; iLenRead = actualDataLen ; DBGOPRINT ( ( obj_t * ) pThis , " " " \n " , pThis -> fd , * padBytes , iLenRead ) ; } else { * padBytes = 0 ; } pThis -> iBufPtrMax = iLenRead ; bRun = 0 ; } } pThis -> iBufPtr = 0 ; finalize_it : RETiRet ; }
read the next buffer from disk
 rgerhards, 2008-02-13
read the next buffer from disk rgerhards 2008 - 02 - 13
/* We need to try read at least twice because we may run into EOF and need
     * to switch files. */ /* first check if we need to (re)open the file. We may have switched to
         * a new one in circular mode or it may have been rewritten (rotated) if
         * we monitor a file rgerhards, 2008-02-13
         */ /* end crypto */ /* good read */ /* here we place our crypto interface */ /* exit loop */ /* if we reach this point, we had a good read */