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/msg.c
rsRetVal MsgReplaceMSG(smsg_t * pThis, const uchar* pszMSG, int lenMSG)
    {
        int lenNew;
        uchar* bufNew;
        DEFiRet;
        ISOBJ_TYPE_assert(pThis, msg);
        assert(pszMSG != NULL);

        lenNew = pThis->iLenRawMsg + lenMSG - pThis->iLenMSG;
        if (lenMSG > pThis->iLenMSG && lenNew >= CONF_RAWMSG_BUFSIZE)
        {
            /*  we have lost our "bet" and need to alloc a new buffer ;) */
            CHKmalloc(bufNew = malloc(lenNew + 1));
            memcpy(bufNew, pThis->pszRawMsg, pThis->offMSG);
            if (pThis->pszRawMsg != pThis->szRawMsg)
                free(pThis->pszRawMsg);
            pThis->pszRawMsg = bufNew;
        }

        if (lenMSG > 0)
            memcpy(pThis->pszRawMsg + pThis->offMSG, pszMSG, lenMSG);
        pThis->pszRawMsg[lenNew] = '\0'; /* this also works with truncation! */
        pThis->iLenRawMsg = lenNew;
        pThis->iLenMSG = lenMSG;

    finalize_it:
        RETiRet;
    }
/* replace the MSG part of a message. The update actually takes place inside
     * rawmsg.
     * There are two cases: either the new message will be larger than the new
     * msg or it will be less than or equal. If it is less than or equal, we can
     * utilize the previous message buffer. If it is larger, we can utilize the
     * smsg_t-included message buffer if it fits in there. If this is not the
     * case, we need to alloc a new, larger, chunk and copy over the data to it.
     * Note that this function is (hopefully) relatively seldom being called, so
     * some performance impact is uncritical. In any case, pszMSG is copied, so
     * if it was dynamically allocated, the caller is responsible for freeing
     * it. rgerhards, 2009-06-23
     */
replace the MSG part of a message. The update actually takes place inside
rawmsg.
There are two cases: either the new message will be larger than the new
msg or it will be less than or equal. If it is less than or equal, we can
utilize the previous message buffer. If it is larger, we can utilize the
smsg_t-included message buffer if it fits in there. If this is not the
case, we need to alloc a new, larger, chunk and copy over the data to it.
Note that this function is (hopefully) relatively seldom being called, so
some performance impact is uncritical. In any case, pszMSG is copied, so
if it was dynamically allocated, the caller is responsible for freeing
it.
replace the MSG part of a message . The update actually takes place inside rawmsg . There are two cases : either the new message will be larger than the new msg or it will be less than or equal . If it is less than or equal we can utilize the previous message buffer . If it is larger we can utilize the smsg_t - included message buffer if it fits in there . If this is not the case we need to alloc a new larger chunk and copy over the data to it . Note that this function is ( hopefully ) relatively seldom being called so some performance impact is uncritical . In any case pszMSG is copied so if it was dynamically allocated the caller is responsible for freeing it .
rsRetVal MsgReplaceMSG(smsg_t * pThis, const uchar* pszMSG, int lenMSG)
    {
        int lenNew;
        uchar* bufNew;
        DEFiRet;
        ISOBJ_TYPE_assert(pThis, msg);
        assert(pszMSG != NULL);
        lenNew = pThis->iLenRawMsg + lenMSG - pThis->iLenMSG;
        if (lenMSG > pThis->iLenMSG && lenNew >= CONF_RAWMSG_BUFSIZE)
        {
            CHKmalloc(bufNew = malloc(lenNew + 1));
            memcpy(bufNew, pThis->pszRawMsg, pThis->offMSG);
            if (pThis->pszRawMsg != pThis->szRawMsg)
                free(pThis->pszRawMsg);
            pThis->pszRawMsg = bufNew;
        }
        if (lenMSG > 0)
            memcpy(pThis->pszRawMsg + pThis->offMSG, pszMSG, lenMSG);
        pThis->pszRawMsg[lenNew] = '\0'; 
        pThis->iLenRawMsg = lenNew;
        pThis->iLenMSG = lenMSG;
    finalize_it:
        RETiRet;
    }
rsRetVal MsgReplaceMSG ( smsg_t * pThis , const uchar * pszMSG , int lenMSG ) { int lenNew ; uchar * bufNew ; DEFiRet ; ISOBJ_TYPE_assert ( pThis , msg ) ; assert ( pszMSG != NULL ) ; lenNew = pThis -> iLenRawMsg + lenMSG - pThis -> iLenMSG ; if ( lenMSG > pThis -> iLenMSG && lenNew >= CONF_RAWMSG_BUFSIZE ) { CHKmalloc ( bufNew = malloc ( lenNew + 1 ) ) ; memcpy ( bufNew , pThis -> pszRawMsg , pThis -> offMSG ) ; if ( pThis -> pszRawMsg != pThis -> szRawMsg ) free ( pThis -> pszRawMsg ) ; pThis -> pszRawMsg = bufNew ; } if ( lenMSG > 0 ) memcpy ( pThis -> pszRawMsg + pThis -> offMSG , pszMSG , lenMSG ) ; pThis -> pszRawMsg [ lenNew ] = ' \0 ' ; pThis -> iLenRawMsg = lenNew ; pThis -> iLenMSG = lenMSG ; finalize_it : RETiRet ; }
replace the MSG part of a message.
replace the MSG part of a message .
/*  we have lost our "bet" and need to alloc a new buffer ;) */ /* this also works with truncation! */