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 doZipWrite(strm_t* pThis, uchar* pBuf, size_t lenBuf,
                           const int bFlush)
{
    int zRet; /* zlib return state */
    DEFiRet;
    unsigned outavail = 0;
    assert(pThis != NULL);
    assert(pBuf != NULL);

    if (!pThis->bzInitDone)
    {
        /* allocate deflate state */
        pThis->zstrm.zalloc = Z_NULL;
        pThis->zstrm.zfree = Z_NULL;
        pThis->zstrm.opaque = Z_NULL;
        /* see note in file header for the params we use with deflateInit2() */
        zRet = zlibw.DeflateInit2(&pThis->zstrm, pThis->iZipLevel, Z_DEFLATED,
                                  31, 9, Z_DEFAULT_STRATEGY);
        if (zRet != Z_OK)
        {
            LogError(0, RS_RET_ZLIB_ERR,
                     "error %d returned from zlib/deflateInit2()", zRet);
            ABORT_FINALIZE(RS_RET_ZLIB_ERR);
        }
        pThis->bzInitDone = RSTRUE;
    }

    /* now doing the compression */
    pThis->zstrm.next_in = (Bytef*)pBuf;
    pThis->zstrm.avail_in = lenBuf;
    /* run deflate() on buffer until everything has been compressed */
    do
    {
        DBGPRINTF("in deflate() loop, avail_in %d, total_in %ld, bFlush %d\n",
                  pThis->zstrm.avail_in, pThis->zstrm.total_in, bFlush);
        pThis->zstrm.avail_out = pThis->sIOBufSize;
        pThis->zstrm.next_out = pThis->pZipBuf;
        zRet = zlibw.Deflate(&pThis->zstrm,
                             bFlush ? Z_SYNC_FLUSH
                                    : Z_NO_FLUSH); /* no bad return value */
        DBGPRINTF("after deflate, ret %d, avail_out %d, to write %d\n", zRet,
                  pThis->zstrm.avail_out, outavail);
        if (zRet != Z_OK)
        {
            LogError(0, RS_RET_ZLIB_ERR,
                     "error %d returned from zlib/Deflate()", zRet);
            ABORT_FINALIZE(RS_RET_ZLIB_ERR);
        }
        outavail = pThis->sIOBufSize - pThis->zstrm.avail_out;
        if (outavail != 0)
        {
            CHKiRet(strmPhysWrite(pThis, (uchar*)pThis->pZipBuf, outavail));
        }
    } while (pThis->zstrm.avail_out == 0);

finalize_it:
    if (pThis->bzInitDone && pThis->bVeryReliableZip)
    {
        doZipFinish(pThis);
    }
    RETiRet;
}
/* write the output buffer in zip mode
 * This means we compress it first and then do a physical write.
 * Note that we always do a full deflateInit ... deflate ... deflateEnd
 * sequence. While this is not optimal, we need to do it because we need
 * to ensure that the file is readable even when we are aborted. Doing the
 * full sequence brings us as far towards this goal as possible (and not
 * doing it would be a total failure). It may be worth considering to
 * add a config switch so that the user can decide the risk he is ready
 * to take, but so far this is not yet implemented (not even requested ;)).
 * rgerhards, 2009-06-04
 */
write the output buffer in zip mode
This means we compress it first and then do a physical write.
Note that we always do a full deflateInit ... deflate ... deflateEnd
sequence. While this is not optimal, we need to do it because we need
to ensure that the file is readable even when we are aborted. Doing the
full sequence brings us as far towards this goal as possible (and not
doing it would be a total failure). It may be worth considering to
add a config switch so that the user can decide the risk he is ready
to take, but so far this is not yet implemented (not even requested ;)).
write the output buffer in zip mode This means we compress it first and then do a physical write . Note that we always do a full deflateInit ... deflate ... deflateEnd sequence . While this is not optimal we need to do it because we need to ensure that the file is readable even when we are aborted . Doing the full sequence brings us as far towards this goal as possible ( and not doing it would be a total failure ) . It may be worth considering to add a config switch so that the user can decide the risk he is ready to take but so far this is not yet implemented ( not even requested ; )) .
static rsRetVal doZipWrite(strm_t* pThis, uchar* pBuf, size_t lenBuf,
                           const int bFlush)
{
    int zRet; 
    DEFiRet;
    unsigned outavail = 0;
    assert(pThis != NULL);
    assert(pBuf != NULL);
    if (!pThis->bzInitDone)
    {
        pThis->zstrm.zalloc = Z_NULL;
        pThis->zstrm.zfree = Z_NULL;
        pThis->zstrm.opaque = Z_NULL;
        zRet = zlibw.DeflateInit2(&pThis->zstrm, pThis->iZipLevel, Z_DEFLATED,
                                  31, 9, Z_DEFAULT_STRATEGY);
        if (zRet != Z_OK)
        {
            LogError(0, RS_RET_ZLIB_ERR,
                     "error %d returned from zlib/deflateInit2()", zRet);
            ABORT_FINALIZE(RS_RET_ZLIB_ERR);
        }
        pThis->bzInitDone = RSTRUE;
    }
    pThis->zstrm.next_in = (Bytef*)pBuf;
    pThis->zstrm.avail_in = lenBuf;
    do
    {
        DBGPRINTF("in deflate() loop, avail_in %d, total_in %ld, bFlush %d\n",
                  pThis->zstrm.avail_in, pThis->zstrm.total_in, bFlush);
        pThis->zstrm.avail_out = pThis->sIOBufSize;
        pThis->zstrm.next_out = pThis->pZipBuf;
        zRet = zlibw.Deflate(&pThis->zstrm,
                             bFlush ? Z_SYNC_FLUSH
                                    : Z_NO_FLUSH); 
        DBGPRINTF("after deflate, ret %d, avail_out %d, to write %d\n", zRet,
                  pThis->zstrm.avail_out, outavail);
        if (zRet != Z_OK)
        {
            LogError(0, RS_RET_ZLIB_ERR,
                     "error %d returned from zlib/Deflate()", zRet);
            ABORT_FINALIZE(RS_RET_ZLIB_ERR);
        }
        outavail = pThis->sIOBufSize - pThis->zstrm.avail_out;
        if (outavail != 0)
        {
            CHKiRet(strmPhysWrite(pThis, (uchar*)pThis->pZipBuf, outavail));
        }
    } while (pThis->zstrm.avail_out == 0);
finalize_it:
    if (pThis->bzInitDone && pThis->bVeryReliableZip)
    {
        doZipFinish(pThis);
    }
    RETiRet;
}
static rsRetVal doZipWrite ( strm_t * pThis , uchar * pBuf , size_t lenBuf , const int bFlush ) { int zRet ; DEFiRet ; unsigned outavail = 0 ; assert ( pThis != NULL ) ; assert ( pBuf != NULL ) ; if ( ! pThis -> bzInitDone ) { pThis -> zstrm . zalloc = Z_NULL ; pThis -> zstrm . zfree = Z_NULL ; pThis -> zstrm . opaque = Z_NULL ; zRet = zlibw . DeflateInit2 ( & pThis -> zstrm , pThis -> iZipLevel , Z_DEFLATED , 31 , 9 , Z_DEFAULT_STRATEGY ) ; if ( zRet != Z_OK ) { LogError ( 0 , RS_RET_ZLIB_ERR , " " , zRet ) ; ABORT_FINALIZE ( RS_RET_ZLIB_ERR ) ; } pThis -> bzInitDone = RSTRUE ; } pThis -> zstrm . next_in = ( Bytef * ) pBuf ; pThis -> zstrm . avail_in = lenBuf ; do { DBGPRINTF ( " \n " , pThis -> zstrm . avail_in , pThis -> zstrm . total_in , bFlush ) ; pThis -> zstrm . avail_out = pThis -> sIOBufSize ; pThis -> zstrm . next_out = pThis -> pZipBuf ; zRet = zlibw . Deflate ( & pThis -> zstrm , bFlush ? Z_SYNC_FLUSH : Z_NO_FLUSH ) ; DBGPRINTF ( " \n " , zRet , pThis -> zstrm . avail_out , outavail ) ; if ( zRet != Z_OK ) { LogError ( 0 , RS_RET_ZLIB_ERR , " " , zRet ) ; ABORT_FINALIZE ( RS_RET_ZLIB_ERR ) ; } outavail = pThis -> sIOBufSize - pThis -> zstrm . avail_out ; if ( outavail != 0 ) { CHKiRet ( strmPhysWrite ( pThis , ( uchar * ) pThis -> pZipBuf , outavail ) ) ; } } while ( pThis -> zstrm . avail_out == 0 ) ; finalize_it : if ( pThis -> bzInitDone && pThis -> bVeryReliableZip ) { doZipFinish ( pThis ) ; } RETiRet ; }
write the output buffer in zip mode
 This means we compress it first and then do a physical write.
write the output buffer in zip mode This means we compress it first and then do a physical write .
/* zlib return state */ /* allocate deflate state */ /* see note in file header for the params we use with deflateInit2() */ /* now doing the compression */ /* run deflate() on buffer until everything has been compressed */ /* no bad return value */