|
|
coherent
lseek() COHERENT System Call lseek()
Set read/write position
lloonngg llsseeeekk(_f_d, _w_h_e_r_e, _h_o_w)
iinntt _f_d, _h_o_w; lloonngg _w_h_e_r_e;
llsseeeekk changes the _s_e_e_k _p_o_s_i_t_i_o_n, or the point within a file where
the next read or write operation is performed. fd is the file's
file descriptor, which is returned by ooppeenn.
where and how describe the new seek position. where gives the
number of bytes that you wish to move the seek position; it is
measured from the beginning of the file if how is zero, from the
current seek position if how is one, or from the end of the file
if how is two. A successful call to lseek returns the new seek
position. For example,
position = lseek(filename, 100L, 0);
moves the seek position 100 bytes past the beginning of the file;
whereas
position = lseek(filename, 0L, 1);
merely returns the current seek position, and does not change the
seek position at all.
Sparse files may be created by seeking beyond the current size of
the file and writing. The ``hole'' between the end of the file
and where the write occurs is read as zero and will occupy no
disk space. For example, if you llsseeeekk 10,000 bytes past the cur-
rent end of file and write a string, the data will be written
10,000 bytes past the old end of file and all intervening matter
will be considered part of the file.
lseek differs from its cousin fseek in that lseek is a system
call and uses a file descriptor, whereas fseek is a C function
and uses a FILE pointer.
***** See Also *****
COHERENT system calls, STDIO
***** Diagnostics *****
lseek returns -1L on an error, such as seeking to a negative
position. If no error occurs, it returns the new seek position.
***** Notes *****
llsseeeekk is permitted on character-special files, but drivers do not
COHERENT Lexicon Page 1
lseek() COHERENT System Call lseek()
generally implement it. As a result, seeking a terminal will not
generate an error but will have no discernible effect.
COHERENT Lexicon Page 2
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.