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 strmOpenFile(strm_t* pThis)
{
    DEFiRet;
    off_t offset;

    assert(pThis != NULL);

    if (pThis->fd != -1)
        ABORT_FINALIZE(RS_RET_OK);

    free(pThis->pszCurrFName);
    pThis->pszCurrFName = NULL; /* used to prevent mem leak in case of error */

    if (pThis->pszFName == NULL)
        ABORT_FINALIZE(RS_RET_FILE_PREFIX_MISSING);

    CHKiRet(strmSetCurrFName(pThis));

    CHKiRet(doPhysOpen(pThis));

    pThis->iCurrOffs = 0;
    pThis->iBufPtrMax = 0;
    CHKiRet(getFileSize(pThis->pszCurrFName, &offset));
    if (pThis->tOperationsMode == STREAMMODE_WRITE_APPEND)
    {
        pThis->iCurrOffs = offset;
    }
    else if (pThis->tOperationsMode == STREAMMODE_WRITE_TRUNC)
    {
        if (offset != 0)
        {
            LogError(0, 0,
                     "file '%s' opened for truncate write, but "
                     "already contains %zd bytes\n",
                     pThis->pszCurrFName, (ssize_t)offset);
        }
    }

    DBGOPRINT((obj_t*)pThis, "opened file '%s' for %s as %d\n",
              pThis->pszCurrFName,
              (pThis->tOperationsMode == STREAMMODE_READ) ? "READ" : "WRITE",
              pThis->fd);

finalize_it:
    if (iRet == RS_RET_OK)
    {
        assert(pThis->fd != -1);
    }
    else
    {
        if (pThis->pszCurrFName != NULL)
        {
            free(pThis->pszCurrFName);
            pThis->pszCurrFName =
                NULL; /* just to prevent mis-adressing down the road... */
        }
        if (pThis->fd != -1)
        {
            close(pThis->fd);
            pThis->fd = -1;
        }
    }
    RETiRet;
}
/* open a strm file
 * It is OK to call this function when the stream is already open. In that
 * case, it returns immediately with RS_RET_OK
 */
open a strm file
It is OK to call this function when the stream is already open. In that
case, it returns immediately with RS_RET_OK
open a strm file It is OK to call this function when the stream is already open . In that case it returns immediately with RS_RET_OK
static rsRetVal strmOpenFile(strm_t* pThis)
{
    DEFiRet;
    off_t offset;
    assert(pThis != NULL);
    if (pThis->fd != -1)
        ABORT_FINALIZE(RS_RET_OK);
    free(pThis->pszCurrFName);
    pThis->pszCurrFName = NULL; 
    if (pThis->pszFName == NULL)
        ABORT_FINALIZE(RS_RET_FILE_PREFIX_MISSING);
    CHKiRet(strmSetCurrFName(pThis));
    CHKiRet(doPhysOpen(pThis));
    pThis->iCurrOffs = 0;
    pThis->iBufPtrMax = 0;
    CHKiRet(getFileSize(pThis->pszCurrFName, &offset));
    if (pThis->tOperationsMode == STREAMMODE_WRITE_APPEND)
    {
        pThis->iCurrOffs = offset;
    }
    else if (pThis->tOperationsMode == STREAMMODE_WRITE_TRUNC)
    {
        if (offset != 0)
        {
            LogError(0, 0,
                     "file '%s' opened for truncate write, but "
                     "already contains %zd bytes\n",
                     pThis->pszCurrFName, (ssize_t)offset);
        }
    }
    DBGOPRINT((obj_t*)pThis, "opened file '%s' for %s as %d\n",
              pThis->pszCurrFName,
              (pThis->tOperationsMode == STREAMMODE_READ) ? "READ" : "WRITE",
              pThis->fd);
finalize_it:
    if (iRet == RS_RET_OK)
    {
        assert(pThis->fd != -1);
    }
    else
    {
        if (pThis->pszCurrFName != NULL)
        {
            free(pThis->pszCurrFName);
            pThis->pszCurrFName =
                NULL; 
        }
        if (pThis->fd != -1)
        {
            close(pThis->fd);
            pThis->fd = -1;
        }
    }
    RETiRet;
}
static rsRetVal strmOpenFile ( strm_t * pThis ) { DEFiRet ; off_t offset ; assert ( pThis != NULL ) ; if ( pThis -> fd != -1 ) ABORT_FINALIZE ( RS_RET_OK ) ; free ( pThis -> pszCurrFName ) ; pThis -> pszCurrFName = NULL ; if ( pThis -> pszFName == NULL ) ABORT_FINALIZE ( RS_RET_FILE_PREFIX_MISSING ) ; CHKiRet ( strmSetCurrFName ( pThis ) ) ; CHKiRet ( doPhysOpen ( pThis ) ) ; pThis -> iCurrOffs = 0 ; pThis -> iBufPtrMax = 0 ; CHKiRet ( getFileSize ( pThis -> pszCurrFName , & offset ) ) ; if ( pThis -> tOperationsMode == STREAMMODE_WRITE_APPEND ) { pThis -> iCurrOffs = offset ; } else if ( pThis -> tOperationsMode == STREAMMODE_WRITE_TRUNC ) { if ( offset != 0 ) { LogError ( 0 , 0 , " " " \n " , pThis -> pszCurrFName , ( ssize_t ) offset ) ; } } DBGOPRINT ( ( obj_t * ) pThis , " \n " , pThis -> pszCurrFName , ( pThis -> tOperationsMode == STREAMMODE_READ ) ? " " : " " , pThis -> fd ) ; finalize_it : if ( iRet == RS_RET_OK ) { assert ( pThis -> fd != -1 ) ; } else { if ( pThis -> pszCurrFName != NULL ) { free ( pThis -> pszCurrFName ) ; pThis -> pszCurrFName = NULL ; } if ( pThis -> fd != -1 ) { close ( pThis -> fd ) ; pThis -> fd = -1 ; } } RETiRet ; }
open a strm file
 It is OK to call this function when the stream is already open.
open a strm file It is OK to call this function when the stream is already open .
/* used to prevent mem leak in case of error */ /* just to prevent mis-adressing down the road... */