

#include <fcntl.h> long lseek(int fn, long offset, int pos);
The synopsis for the POSIX implementation is
#include <unistd.h> off_t lseek(int fn, off_t offset, int pos);
lseek replaces the current offset with a new position in the
file. fn is the file descriptor. offset is the specified
byte offset; it can be positive or negative. pos is the
position from which offset is specified. The next I/O
operation on the file begins at offset.
pos can be one of the following symbols defined in
<unistd.h> and <fcntl.h>:
SEEK_SET
SEEK_CUR
SEEK_END
lseek(fn, 0L, SEEK_CUR) determines the current
file position without changing it. You can use lseek to set
the position past the current end of file, but after such positioning,
attempts to read data shows end of file. If you call write
while the file is so positioned, 0s are written into all character
positions between the previous end of file and the current position,
after which the specified data are written.
If fn represents a non-HFS file opened as text, offset does not
represent a physical offset in bytes. In this case, the lseek offset is
interpreted according to the same rules as an fseek offset. For more
information, see File positioning with standard I/O (fseek and ftell) .
lseek returns the new file position; otherwise, it returns
- 1L.
lseek:
#include <fcntl.h>
main()
{
long size;
int fileno;
fileno = open("tso:TEST", O_RDONLY);
/* accesses the file as binary */
if ((size = lseek(fileno, 0L, SEEK_END)) == -1)
perror("lseek() error");
else {
printf("Size of file is: %ldn", size);
close(fileno);
}
}
fgetpos, fseek, fsetpos, ftell, ksearch,
kseek
Copyright (c) 1998 SAS Institute Inc. Cary, NC, USA. All rights reserved.