FreeRTOS-Plus/ThirdParty/WolfSSL-FIPS-Ready/wolfcrypt/src/wc_port.c
/* Helpful function to load file into allocated buffer */
Helpful function to load file into allocated buffer
Helpful function to load file into allocated buffer
int wc_FileLoad(const char* fname, unsigned char** buf, size_t* bufLen, 
    void* heap)
{
    int ret;
    size_t fileSz;
    XFILE f;
    if (fname == NULL || buf == NULL || bufLen == NULL) {
        return BAD_FUNC_ARG;
    }
    *buf = NULL;
    *bufLen = 0;
    f = XFOPEN(fname, "rb");
    if (!f) {
        WOLFSSL_MSG("wc_LoadFile file load error");
        return BAD_PATH_ERROR;
    }
    XFSEEK(f, 0, SEEK_END);
    fileSz = XFTELL(f);
    XREWIND(f);
    if (fileSz > 0) {
        *bufLen = fileSz;
        *buf = (byte*)XMALLOC(*bufLen, heap, DYNAMIC_TYPE_TMP_BUFFER);
        if (*buf == NULL) {
            WOLFSSL_MSG("wc_LoadFile memory error");
            ret = MEMORY_E;
        }
        else {
            size_t readLen = XFREAD(*buf, 1, *bufLen, f);
            ret = (readLen == *bufLen) ? 0 : -1;
        }
    }
    else {
        ret = BUFFER_E;
    }
    XFCLOSE(f);
    (void)heap;
    return ret;
}
int wc_FileLoad ( const char * fname , unsigned char * * buf , size_t * bufLen , void * heap ) { int ret ; size_t fileSz ; XFILE f ; if ( fname == NULL || buf == NULL || bufLen == NULL ) { return BAD_FUNC_ARG ; } * buf = NULL ; * bufLen = 0 ; f = XFOPEN ( fname , " " ) ; if ( ! f ) { WOLFSSL_MSG ( " " ) ; return BAD_PATH_ERROR ; } XFSEEK ( f , 0 , SEEK_END ) ; fileSz = XFTELL ( f ) ; XREWIND ( f ) ; if ( fileSz > 0 ) { * bufLen = fileSz ; * buf = ( byte * ) XMALLOC ( * bufLen , heap , DYNAMIC_TYPE_TMP_BUFFER ) ; if ( * buf == NULL ) { WOLFSSL_MSG ( " " ) ; ret = MEMORY_E ; } else { size_t readLen = XFREAD ( * buf , 1 , * bufLen , f ) ; ret = ( readLen == * bufLen ) ? 0 : -1 ; } } else { ret = BUFFER_E ; } XFCLOSE ( f ) ; ( void ) heap ; return ret ; }
Helpful function to load file into allocated buffer
Helpful function to load file into allocated buffer
/* set defaults */ /* open file (read-only binary) */ /* check response code */