/* ======================================== * * Copyright YOUR COMPANY, THE YEAR * All Rights Reserved * UNPUBLISHED, LICENSED SOFTWARE. * * CONFIDENTIAL AND PROPRIETARY INFORMATION * WHICH IS THE PROPERTY OF your company. * * ======================================== */ #include "ff_headers.h" #include "ff_stdio.h" // Create a file of size "size" bytes filled with random data seeded with "seed" void create_big_file(const char *const pathname, size_t size, unsigned seed) { int32_t lItems; FF_FILE *pxFile; configASSERT(0 == size % sizeof(int)); srand(seed); /* Open the file, creating the file if it does not already exist. */ pxFile = ff_fopen( pathname, "w" ); if (!pxFile) FF_PRINTF("ff_fopen(%s): %s (%d)\r\r\n", pathname, strerror(stdioGET_ERRNO()), -stdioGET_ERRNO()); configASSERT( pxFile ); FF_PRINTF("Writing...\n"); size_t i; int val; for (i = 0; i < size/sizeof(val); ++i) { val = rand(); lItems = ff_fwrite( &val, sizeof(val), 1, pxFile ); if (lItems < 1) FF_PRINTF("ff_fwrite(%s): %s (%d)\r\r\n", pathname, strerror(stdioGET_ERRNO()), -stdioGET_ERRNO()); configASSERT( lItems == 1 ); } /* Close the file. */ ff_fclose( pxFile ); } // Read a file of size "size" bytes filled with random data seeded with "seed" and verify the data void check_big_file(const char *const pathname, size_t size, uint32_t seed) { int32_t lItems; FF_FILE *pxFile; configASSERT(0 == size % sizeof(int)); srand(seed); /* Open the file, creating the file if it does not already exist. */ pxFile = ff_fopen( pathname, "r" ); if (!pxFile) FF_PRINTF("ff_fopen(%s): %s (%d)\r\r\n", pathname, strerror(stdioGET_ERRNO()), -stdioGET_ERRNO()); configASSERT( pxFile ); FF_PRINTF("Reading...\n"); size_t i; int val; for (i = 0; i < size/sizeof(val); ++i) { lItems = ff_fread( &val, sizeof(val), 1, pxFile ); if (lItems < 1) FF_PRINTF("ff_fread(%s): %s (%d)\r\r\n", pathname, strerror(stdioGET_ERRNO()), -stdioGET_ERRNO()); configASSERT( lItems == 1 ); /* Check the buffer is filled with the expected data. */ int expected = rand(); if (val != expected) FF_PRINTF("Data mismatch at word %lu: expected=%d val=%d\n", i, expected, val); } /* Close the file. */ ff_fclose( pxFile ); } void big_file_test(const char *const pathname, size_t size, uint32_t seed) { create_big_file(pathname, size, seed); check_big_file(pathname, size, seed); } /* [] END OF FILE */