ff_stdio.h
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:
Letter
|
Mode
|
"r"
|
Open the file for reading only.
|
"r+"
|
Open the file for reading and writing.
|
"w"
|
Open a file for writing. If the file already exists it will
be truncated to zero length. If the file does not already
exist it will be created.
|
"a"
|
Open a file for writing. If the file
already exists then new data will be appended to the
end of the file. If the file does not already exist
it will be created.
|
"a+"
|
Open a file for reading and writing. If the file
already exists then new data will be appended to the
end of the file. If the file does not already exist
it will be created.
|
Files are always opened in binary mode.
|
Returns:
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 stdioGET_ERRNO()
API function.
Example usage:
BaseType_t xCopyFile( char *pcSourceFileName, char *pcDestinationFileName )
{
FF_FILE *pxSourceFile, *pxDestinationFile;
size_t xCount;
uint32_t ucBuffer[ 50 ];
pxSourceFile = ff_fopen( pcSourceFileName, "r" );
if( pxSourceFile != NULL )
{
pxDestinationFile = ff_fopen( pcDestinationFileName, "w+" );
if( pxDestinationFile != NULL )
{
for( ;; )
{
xCount = ff_fread( ucBuffer, 1, sizeof( ucBuffer ), pxSourceFile );
ff_fwrite( ucBuffer, xCount, 1, pxDestinationFile );
if( xCount < sizeof( ucBuffer ) )
{
break;
}
}
ff_fclose( pxDestinationFile );
}
ff_fclose( pxSourceFile );
}
}
Example use of the ff_fopen() API function to open or create a file
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.