OtaPalStatus_t otaPal_CreateFileForRx()

in platform/posix/ota_pal/source/ota_pal_posix.c [413:469]


OtaPalStatus_t otaPal_CreateFileForRx( OtaFileContext_t * const C )
{
    OtaPalStatus_t result = OTA_PAL_COMBINE_ERR( OtaPalUninitialized, 0 );
    char realFilePath[ OTA_FILE_PATH_LENGTH_MAX ];
    OtaPalPathGenStatus_t status = OtaPalFileGenSuccess;

    if( C != NULL )
    {
        if( C->pFilePath != NULL )
        {
            if( C->pFilePath[ 0 ] != ( uint8_t ) '/' )
            {
                status = getFilePathFromCWD( realFilePath, ( const char * ) C->pFilePath );
            }
            else
            {
                ( void ) strncpy( realFilePath, ( const char * ) C->pFilePath, strlen( ( const char * ) C->pFilePath ) + 1U );
            }

            if( status == OtaPalFileGenSuccess )
            {
                /* POSIX port using standard library */
                /* coverity[misra_c_2012_rule_21_6_violation] */
                C->pFile = fopen( ( const char * ) realFilePath, "w+b" );

                if( C->pFile != NULL )
                {
                    result = OTA_PAL_COMBINE_ERR( OtaPalSuccess, 0 );
                    LogInfo( ( "Receive file created." ) );
                }
                else
                {
                    result = OTA_PAL_COMBINE_ERR( OtaPalRxFileCreateFailed, errno );
                    LogError( ( "Failed to start operation: Operation already started. failed to open -- %s Path ", C->pFilePath ) );
                }
            }
            else
            {
                LogError( ( "Could not generate the absolute path for the file" ) );
                result = OTA_PAL_COMBINE_ERR( OtaPalRxFileCreateFailed, 0 );
            }
        }
        else
        {
            result = OTA_PAL_COMBINE_ERR( OtaPalRxFileCreateFailed, 0 );
            LogError( ( "Invalid file path provided." ) );
        }
    }
    else
    {
        result = OTA_PAL_COMBINE_ERR( OtaPalRxFileCreateFailed, 0 );
        LogError( ( "Invalid context provided." ) );
    }

    /* Exiting function without calling fclose. Context file handle state is managed by this API. */
    return result;
}