gtpc2m4n | C/C++ Language Support User's Guide |
This function sets the file offset.
Format
#include <unistd.h> off_t lseek(int fildes,off_t offset,int pos);
Specify one of the following symbols (defined in the unistd.h header file):
The new position is the byte offset from the position specified by pos. After you have used the lseek function to seek to a new location, the next I/O operation on the file begins at that location.
The lseek function lets you specify new file offsets beyond the current end of the file. If data is written at such a point, read operations in the gap between this data and the old end of the file will return bytes containing zeros. (In other words, the gap is assumed to be filled with zeros.)
Seeking past the end of a file, however, does not automatically extend the length of the file. There must be a write operation before the file is actually extended.
Normal Return
If successful, the lseek function returns the new file offset, measured in bytes, from the beginning of the file.
Error Return
If unsuccessful, the lseek function returns a value of -1 and sets errno to one of the following:
Programming Considerations
Examples
The following example positions a file (that has at least 10 bytes) to an offset of 10 bytes before the end of the file.
lseek(fildes,-10,SEEK_END);
Related Information
See Appendix E, Programming Support for the TPF File System for more information about TPF File System C Functions.