LSEEK(3)                   POSIX Programmer's Manual                  LSEEK(3)



PPRROOLLOOGG
       This manual page is part of the POSIX Programmer's Manual.  The OS
       implementation of this interface may differ (consult the corresponding
       OS manual page for details of OS behavior), or the interface may not be
       implemented on OS.

NNAAMMEE
       lseek -- move the read/write file offset

SSYYNNOOPPSSIISS
       #include <unistd.h>

       off_t lseek(int _f_i_l_d_e_s, off_t _o_f_f_s_e_t, int _w_h_e_n_c_e);

DDEESSCCRRIIPPTTIIOONN
       The _l_s_e_e_k() function shall set the file offset for the open file
       description associated with the file descriptor _f_i_l_d_e_s_, as follows:

        *  If _w_h_e_n_c_e is SEEK_SET, the file offset shall be set to _o_f_f_s_e_t
           bytes.

        *  If _w_h_e_n_c_e is SEEK_CUR, the file offset shall be set to its current
           location plus _o_f_f_s_e_t.

        *  If _w_h_e_n_c_e is SEEK_END, the file offset shall be set to the size of
           the file plus _o_f_f_s_e_t.

       The symbolic constants SEEK_SET, SEEK_CUR, and SEEK_END are defined in
       _<_u_n_i_s_t_d_._h_>.

       The behavior of _l_s_e_e_k() on devices which are incapable of seeking is
       implementation-defined.  The value of the file offset associated with
       such a device is undefined.

       The _l_s_e_e_k() function shall allow the file offset to be set beyond the
       end of the existing data in the file. If data is later written at this
       point, subsequent reads of data in the gap shall return bytes with the
       value 0 until data is actually written into the gap.

       The _l_s_e_e_k() function shall not, by itself, extend the size of a file.

       If _f_i_l_d_e_s refers to a shared memory object, the result of the _l_s_e_e_k()
       function is unspecified.

       If _f_i_l_d_e_s refers to a typed memory object, the result of the _l_s_e_e_k()
       function is unspecified.

RREETTUURRNN VVAALLUUEE
       Upon successful completion, the resulting offset, as measured in bytes
       from the beginning of the file, shall be returned. Otherwise, -1 shall
       be returned, _e_r_r_n_o shall be set to indicate the error, and the file
       offset shall remain unchanged.

EERRRROORRSS
       The _l_s_e_e_k() function shall fail if:

       EEBBAADDFF  The _f_i_l_d_e_s argument is not an open file descriptor.

       EEIINNVVAALL The _w_h_e_n_c_e argument is not a proper value, or the resulting file
              offset would be negative for a regular file, block special file,
              or directory.

       EEOOVVEERRFFLLOOWW
              The resulting file offset would be a value which cannot be
              represented correctly in an object of type ooffff__tt.

       EESSPPIIPPEE The _f_i_l_d_e_s argument is associated with a pipe, FIFO, or socket.

       _T_h_e _f_o_l_l_o_w_i_n_g _s_e_c_t_i_o_n_s _a_r_e _i_n_f_o_r_m_a_t_i_v_e_.

EEXXAAMMPPLLEESS
       None.

AAPPPPLLIICCAATTIIOONN UUSSAAGGEE
       None.

RRAATTIIOONNAALLEE
       The ISO C standard includes the functions _f_g_e_t_p_o_s() and _f_s_e_t_p_o_s(),
       which work on very large files by use of a special positioning type.

       Although _l_s_e_e_k() may position the file offset beyond the end of the
       file, this function does not itself extend the size of the file. While
       the only function in POSIX.1-2008 that may directly extend the size of
       the file is _w_r_i_t_e(), _t_r_u_n_c_a_t_e(), and _f_t_r_u_n_c_a_t_e(), several functions
       originally derived from the ISO C standard, such as _f_w_r_i_t_e(),
       _f_p_r_i_n_t_f(), and so on, may do so (by causing calls on _w_r_i_t_e()).

       An invalid file offset that would cause [[EEIINNVVAALL]] to be returned may be
       both implementation-defined and device-dependent (for example, memory
       may have few invalid values). A negative file offset may be valid for
       some devices in some implementations.

       The POSIX.1-1990 standard did not specifically prohibit _l_s_e_e_k() from
       returning a negative offset. Therefore, an application was required to
       clear _e_r_r_n_o prior to the call and check _e_r_r_n_o upon return to determine
       whether a return value of (ooffff__tt)-1 is a negative offset or an
       indication of an error condition. The standard developers did not wish
       to require this action on the part of a conforming application, and
       chose to require that _e_r_r_n_o be set to [[EEIINNVVAALL]] when the resulting file
       offset would be negative for a regular file, block special file, or
       directory.

FFUUTTUURREE DDIIRREECCTTIIOONNSS
       None.

SSEEEE AALLSSOO
       _o_p_e_n()

       The Base Definitions volume of POSIX.1-2017, <<ssyyss__ttyyppeess..hh>>, <<uunniissttdd..hh>>

CCOOPPYYRRIIGGHHTT
       Portions of this text are reprinted and reproduced in electronic form
       from IEEE Std 1003.1-2017, Standard for Information Technology --
       Portable Operating System Interface (POSIX), The Open Group Base
       Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the
       Institute of Electrical and Electronics Engineers, Inc and The Open
       Group.  In the event of any discrepancy between this version and the
       original IEEE and The Open Group Standard, the original IEEE and The
       Open Group Standard is the referee document. The original Standard can
       be obtained online at http://www.opengroup.org/unix/online.html .

       Any typographical or formatting errors that appear in this page are
       most likely to have been introduced during the conversion of the source
       files to man page format. To report such errors, see
       https://www.kernel.org/doc/man-pages/reporting_bugs.html .



IEEE/The Open Group                  2017                             LSEEK(3)
