Real time embedded FreeRTOS RSS feed 
Homepage FreeRTOS+ Products FreeRTOS Labs Support Forum Contact / Enquiries

f_seek()

[FreeRTOS Embedded File System API]

header_file.h
unsigned char f_seek( F_FILE *pxFileHandle, long lOffset, unsigned char ucWhence );
		

Moves the current file read/write position in an open FAT file.

Parameters:

pxFileHandle   The handle of the file in which the current file read/write position is being moved. The handle is returned from the call to f_open() used to originally open the file.

lOffset   The byte position (relative to the ucWhence parameter) to which the current file position will be moved.

ucWhence   The absolute position from which the lOffset parameter is relative. Valid values are:

Value
Description
F_SEEK_CUR The current file position.
F_SEEK_END The end of the file.
F_SEEK_SET The beginning of the file.

Returns:
F_NO_ERROR   The current file read/write position was successfully moved.

Any other value   The current file read/write position was not successfully moved. The returned value holds the error code.

See also

f_tell()

Example usage:


void vSampleFunction( char *pcFileName, char *pcBuffer )
{
F_FILE *pxFile;

    /* Open the file specified by the pcFileName parameter. */
    pxFile = f_open( pcFileName, "r" );

    if( pxFile != NULL )
    {
        /* Read one byte from the opened file. */
        f_read( pcBuffer, 1, 1, pxFile );

        /* Move the current file position back to the very start of the file. */
        f_seek( pxFile, 0, F_SEEK_SET );

        /* Read a byte again.  As the file position was moved back to the start
        of the file the byte that is read is the same byte read by the first
        f_read() call. */
        f_read( pcBuffer, 1, 1, pxFile );

        /* This time move the current position to the very end of the file. */
        f_seek( pxFile, -1, F_SEEK_END );

        /* Now the byte read is the last byte in the file. */
        f_read( pcBuffer, 1, 1, pxFile );

        /* Finished with the file, close it. */
        f_close( pxFile );
    }
}
						
Example use of the f_seek() API function


[ Back to the top ]    [ About FreeRTOS ]    [ Privacy ]    [ FreeRTOS+ Sitemap ]    [ Main FreeRTOS Sitemap ]    [ ]


Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.