
File I/O Support for Embedded Systems
2-21
Operating System Abstraction API
Read from a File
efs_fread
Syntax
size_t efs_fread( void *ptr, size_t size, size_t nobj, EFS_FILE *stream );
Parameter(s)
ptr
Pointer to data buffer to receive data
size
Size in bytes of a read “object”
nobj
Number of objects to read
stream
Pointer to open stream (file)
Return Value
Returns the number of objects read
Description
This function reads from the indicated stream in the array ptr at most nobj ob-
jects of a length specified by size. It returns the number of objects read; this
may be less than the number of objects requested. It is functionally equivalent
to fread().
efs_feof() can be used to detect end of file.
Set File Position
efs_fseek
Syntax
INT32 efs_fseek( EFS_FILE *stream, INT32 offset, int origin );
Parameter(s)
stream
Pointer to open stream (file)
offset
Offset of desired new position
origin
Base reference point for offset
Return Value
Returns non-zero on error
Description
This function sets the file position of the indicated stream to that specified by
offset from a base reference point specified by origin. It is functionally equiva-
lent to fseek().
The origin parameter can be set to one of the following:
-
EFS_SEEK_SET – Position by offset from the beginning of the file
-
EFS_SEEK_CUR – Position by offset from the current position
-
EFS_SEEK_END – Position by offset from the end of the file
Get File Position
efs_ftell
Syntax
INT32 efs_ftell( EFS_FILE *stream );
Parameter(s)
stream
Pointer to open stream (file)
Return Value
Returns file position or –1L on error
Description
This function returns the current file position of the indicated stream. It is func-
tionally equivalent to ftell().