Example #1
0
rv_decode*
rv_decode_create2(void*               pUserError,
                  rm_error_func_ptr   fpError,
                  void*               pUserMem,
                  rm_malloc_func_ptr  fpMalloc,
                  rm_free_func_ptr    fpFree)
{
    rv_decode* pRet = (rv_decode*)HXNULL;

    if (fpMalloc && fpFree)
    {
        pRet = (rv_decode*) fpMalloc(pUserMem, sizeof(rv_decode));

        if (pRet)
        {
            /* Zero out the struct */
            memset((void*) pRet, 0, sizeof(rv_decode));
            /* Assign the error function */
            pRet->fpError = fpError;
            pRet->pUserError = pUserError;
            /* Assign the memory functions */
            pRet->fpMalloc = fpMalloc;
            pRet->fpFree = fpFree;
            pRet->pUserMem = pUserMem;

            /* Allocate the backend interface struct */
            pRet->pDecode = (rv_backend*) fpMalloc(pUserMem, sizeof(rv_backend));

            if (pRet->pDecode == HXNULL)
            {
                fpFree(pUserMem, pRet);
                pRet = (rv_decode *)HXNULL;
            }
        }
    }

    return pRet;
}
rm_parser* rm_parser_create2(void*              pError,
                             rm_error_func_ptr  fpError,
                             void*              pMem,
                             rm_malloc_func_ptr fpMalloc,
                             rm_free_func_ptr   fpFree)
{
    rm_parser* pRet = HXNULL;

    if (fpMalloc)
    {
        /* Allocate space for the rm_parser_internal struct
         * by using the passed-in malloc function
         */
        rm_parser_internal* pInt = (rm_parser_internal*) fpMalloc(pMem, sizeof(rm_parser_internal));
        if (pInt)
        {
            /* Zero out the struct */
            memset((void*) pInt, 0, sizeof(rm_parser_internal));
            /*
             * Assign the error members. If the user did not
             * provide an error callback, then use the default
             * rm_error_default().
             */
            if (fpError)
            {
                pInt->fpError    = fpError;
                pInt->pUserError = pError;
            }
            else
            {
                pInt->fpError    = rm_error_default;
                pInt->pUserError = HXNULL;
            }
            /* Assign the memory functions */
            pInt->fpMalloc = fpMalloc;
            pInt->fpFree   = fpFree;
            pInt->pUserMem = pMem;
            /* Assign the return value */
            pRet = (rm_parser*) pInt;
        }
    }

    return pRet;
}
Example #3
0
BYTE* copy_buffer(void*              pUserMem,
                  rm_malloc_func_ptr fpMalloc,
                  BYTE*              pBuf,
                  UINT32             ulLen)
{
    BYTE* pRet = (BYTE*)HXNULL;

    if (fpMalloc && pBuf && ulLen)
    {
        /* Allocate a buffer */
        pRet = (BYTE*) fpMalloc(pUserMem, ulLen);
        if (pRet)
        {
            /* Copy the buffer */
            memcpy(pRet, pBuf, ulLen);
        }
    }

    return pRet;
}