FF_FILE *ff_fopen( const char *pcFile, const char *pcMode );
Opens a file in the embedded FAT file system.
Parameters:
| pcFile |
A pointer to a standard null terminated C string that holds
the name of the file being opened. The string
can include a relative path.
|
||||||||||||
| pcMode |
A string that sets the mode in which the file is opened.
Valid strings include:
Files are always opened in binary mode.
|
If the file was opened successfully then a pointer to the file is returned.
If the file could not be opened then NULL is returned and the task's errno is set to indicate the reason. A task can obtain its errno value using the ff_errno() API function.
Example usage:
BaseType_t xCopyFile( char *pcSourceFileName, char *pcDestinationFileName ) { FF_FILE *pxSourceFile, *pxDestinationFile; size_t xCount; uint32_t ucBuffer[ 50 ]; /* Open the source file in read only mode. */ pxSourceFile = ff_fopen( pcSourceFileName, "r" ); if( pxSourceFile != NULL ) { /* Create or overwrite a writable file. */ pxDestinationFile = ff_fopen( pcDestinationFileName, "w+" ); if( pxDestinationFile != NULL ) { for( ;; ) { /* Read sizeof( ucBuffer ) bytes from the source file into a buffer. */ xCount = ff_fread( ucBuffer, 1, sizeof( ucBuffer ), pxSourceFile ); /* Write however many bytes were read from the source file into the destination file. */ ff_fwrite( ucBuffer, xCount, 1, pxDestinationFile ); if( xCount < sizeof( ucBuffer ) ) { /* The end of the flie was reached. */ break; } } /* Close the destination file. */ ff_fclose( pxDestinationFile ); } /* Close the source file. */ ff_fclose( pxSourceFile ); } } Example use of the ff_fopen() API function to open or create a file