7.10 lseek Function

Move a file pointer to a specified location.

Attention: This interface function is not implemented by MPLAB XC8 C compilers.

Include

<unistd.h>

Prototype

long lseek(int handle, long offset, int origin);

Arguments

handle
handle (file descriptor) referring to an opened file
offset
the number of characters from the origin
origin
the position from which to start the seek

Return Value

Returns the offset, in characters, of the new position from the beginning of the file. The function returns -1 to indicate an error and sets errno. Appropriate values might be EBADF or EINVAL.

Remarks

This function is implemented as a stub that must be completed to suit the application.

This helper function is called by the Standard C Library functions fgetpos(), ftell(), fseek(), fsetpos and rewind().

The origin argument may be one of the following values (as defined in <stdio.h>):
Origin
SEEK_SETBeginning of file
SEEK_CURCurrent position of file pointer
SEEK_ENDEnd-of-file

Default Behavior

As distributed, the parameters are passed to the host file system through the simulator. The return value is the value returned by the host file system.

Source File

lseek.c