#include <unistd.h>
|
off_t
lseek (int fildes, off_t offset, int whence); |
If whence is SEEK_SET, the offset is set to offset bytes. | |
If whence is SEEK_CUR, the offset is set to its current location plus offset bytes. | |
If whence is SEEK_END, the offset is set to the size of the file plus offset bytes. | |
Note : lseek function allows the file offset to be set beyond the existing end-of-file, data in the seeked slot is undefined, and hence the read operation in seeked slot is undefined untill data is actually written into it. lseek beyond existing end-of-file increases the file size accordingly.
/** * Detailed description : Example for lseek usage. **/ #include <stdio.h> #include <sys/stat.h> #include <fcntl.h> #include <sys/types.h> int main() { int fd = 0; fd = open("lseek.txt" , O_CREAT | O_RDWR , 0666); if(lseek(fd , 0 , SEEK_SET) < 0 ) { printf("Lseek on file lseek.txt failed \n"); return -1; } printf("Lseek on lseek.txt passed "); return 0; }
Output
Lseek on lseek.txt passed
[EBADF] | |
The fildes argument is not an open file descriptor. | |
[EINVAL] | |
The whence argument is not a proper value or the resulting file offset would be negative for a non-character special file. | |
[EOVERFLOW] | |
The resulting file offset would be a value which cannot be represented correctly in an object of type off_t(Not supported). | |
[ESPIPE] | |
The fildes argument is associated with a pipe, socket, or FIFO. | |
© 2005-2007 Nokia |