Files
2024-02-19 00:21:47 -05:00

216 lines
8.5 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta name="generator" content="HTML Tidy, see www.w3.org">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group's rhtm tool v1.2.1 -->
<!-- Copyright (c) 2001 The Open Group, All Rights Reserved -->
<title>lseek</title>
</head>
<body bgcolor="white">
<script type="text/javascript" language="JavaScript" src="../jscript/codes.js">
</script>
<basefont size="3"> <a name="lseek"></a> <a name="tag_03_354"></a><!-- lseek -->
<!--header start-->
<center><font size="2">The Open Group Base Specifications Issue 6<br>
IEEE Std 1003.1-2001<br>
Copyright &copy; 2001 The IEEE and The Open Group, All Rights reserved.</font></center>
<!--header end-->
<hr size="2" noshade>
<h4><a name="tag_03_354_01"></a>NAME</h4>
<blockquote>lseek - move the read/write file offset</blockquote>
<h4><a name="tag_03_354_02"></a>SYNOPSIS</h4>
<blockquote class="synopsis">
<p><code><tt>#include &lt;<a href="../basedefs/unistd.h.html">unistd.h</a>&gt;<br>
<br>
off_t lseek(int</tt> <i>fildes</i><tt>, off_t</tt> <i>offset</i><tt>, int</tt> <i>whence</i><tt>);<br>
</tt></code></p>
</blockquote>
<h4><a name="tag_03_354_03"></a>DESCRIPTION</h4>
<blockquote>
<p>The <i>lseek</i>() function shall set the file offset for the open file description associated with the file descriptor
<i>fildes,</i> as follows:</p>
<ul>
<li>
<p>If <i>whence</i> is SEEK_SET, the file offset shall be set to <i>offset</i> bytes.</p>
</li>
<li>
<p>If <i>whence</i> is SEEK_CUR, the file offset shall be set to its current location plus <i>offset</i>.</p>
</li>
<li>
<p>If <i>whence</i> is SEEK_END, the file offset shall be set to the size of the file plus <i>offset</i>.</p>
</li>
</ul>
<p>The symbolic constants SEEK_SET, SEEK_CUR, and SEEK_END are defined in <a href=
"../basedefs/unistd.h.html"><i>&lt;unistd.h&gt;</i></a>.</p>
<p>The behavior of <i>lseek</i>() on devices which are incapable of seeking is implementation-defined. The value of the file offset
associated with such a device is undefined.</p>
<p>The <i>lseek</i>() 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.</p>
<p>The <i>lseek</i>() function shall not, by itself, extend the size of a file.</p>
<p><sup>[<a href="javascript:open_code('SHM')">SHM</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
If <i>fildes</i> refers to a shared memory object, the result of the <i>lseek</i>() function is unspecified. <img src=
"../images/opt-end.gif" alt="[Option End]" border="0"></p>
<p><sup>[<a href="javascript:open_code('TYM')">TYM</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
If <i>fildes</i> refers to a typed memory object, the result of the <i>lseek</i>() function is unspecified. <img src=
"../images/opt-end.gif" alt="[Option End]" border="0"></p>
</blockquote>
<h4><a name="tag_03_354_04"></a>RETURN VALUE</h4>
<blockquote>
<p>Upon successful completion, the resulting offset, as measured in bytes from the beginning of the file, shall be returned.
Otherwise, (<b>off_t</b>)-1 shall be returned, <i>errno</i> shall be set to indicate the error, and the file offset shall remain
unchanged.</p>
</blockquote>
<h4><a name="tag_03_354_05"></a>ERRORS</h4>
<blockquote>
<p>The <i>lseek</i>() function shall fail if:</p>
<dl compact>
<dt>[EBADF]</dt>
<dd>The <i>fildes</i> argument is not an open file descriptor.</dd>
<dt>[EINVAL]</dt>
<dd>The <i>whence</i> argument is not a proper value, or the resulting file offset would be negative for a regular file, block
special file, or directory.</dd>
<dt>[EOVERFLOW]</dt>
<dd>The resulting file offset would be a value which cannot be represented correctly in an object of type <b>off_t</b>.</dd>
<dt>[ESPIPE]</dt>
<dd>The <i>fildes</i> argument is associated with a pipe, FIFO, or socket.</dd>
</dl>
</blockquote>
<hr>
<div class="box"><em>The following sections are informative.</em></div>
<h4><a name="tag_03_354_06"></a>EXAMPLES</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_03_354_07"></a>APPLICATION USAGE</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_03_354_08"></a>RATIONALE</h4>
<blockquote>
<p>The ISO&nbsp;C standard includes the functions <a href="../functions/fgetpos.html"><i>fgetpos</i>()</a> and <a href=
"../functions/fsetpos.html"><i>fsetpos</i>()</a>, which work on very large files by use of a special positioning type.</p>
<p>Although <i>lseek</i>() 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 IEEE&nbsp;Std&nbsp;1003.1-2001 that may directly extend the size of the file is <a href=
"../functions/write.html"><i>write</i>()</a>, <a href="../functions/truncate.html"><i>truncate</i>()</a>, and <a href=
"../functions/ftruncate.html"><i>ftruncate</i>()</a>, several functions originally derived from the ISO&nbsp;C standard, such as <a
href="../functions/fwrite.html"><i>fwrite</i>()</a>, <a href="../functions/fprintf.html"><i>fprintf</i>()</a>, and so on, may do so
(by causing calls on <a href="../functions/write.html"><i>write</i>()</a>).</p>
<p>An invalid file offset that would cause [EINVAL] 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.</p>
<p>The POSIX.1-1990 standard did not specifically prohibit <i>lseek</i>() from returning a negative offset. Therefore, an
application was required to clear <i>errno</i> prior to the call and check <i>errno</i> upon return to determine whether a return
value of ( <b>off_t</b>)-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 <i>errno</i> be set to [EINVAL] when the
resulting file offset would be negative for a regular file, block special file, or directory.</p>
</blockquote>
<h4><a name="tag_03_354_09"></a>FUTURE DIRECTIONS</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_03_354_10"></a>SEE ALSO</h4>
<blockquote>
<p><a href="open.html"><i>open</i>()</a> , the Base Definitions volume of IEEE&nbsp;Std&nbsp;1003.1-2001, <a href=
"../basedefs/sys/types.h.html"><i>&lt;sys/types.h&gt;</i></a>, <a href="../basedefs/unistd.h.html"><i>&lt;unistd.h&gt;</i></a></p>
</blockquote>
<h4><a name="tag_03_354_11"></a>CHANGE HISTORY</h4>
<blockquote>
<p>First released in Issue 1. Derived from Issue 1 of the SVID.</p>
</blockquote>
<h4><a name="tag_03_354_12"></a>Issue 5</h4>
<blockquote>
<p>The DESCRIPTION is updated for alignment with the POSIX Realtime Extension.</p>
<p>Large File Summit extensions are added.</p>
</blockquote>
<h4><a name="tag_03_354_13"></a>Issue 6</h4>
<blockquote>
<p>In the SYNOPSIS, the optional include of the <a href="../basedefs/sys/types.h.html"><i>&lt;sys/types.h&gt;</i></a> header is
removed.</p>
<p>The following new requirements on POSIX implementations derive from alignment with the Single UNIX Specification:</p>
<ul>
<li>
<p>The requirement to include <a href="../basedefs/sys/types.h.html"><i>&lt;sys/types.h&gt;</i></a> has been removed. Although <a
href="../basedefs/sys/types.h.html"><i>&lt;sys/types.h&gt;</i></a> was required for conforming implementations of previous POSIX
specifications, it was not required for UNIX applications.</p>
</li>
<li>
<p>The [EOVERFLOW] error condition is added. This change is to support large files.</p>
</li>
</ul>
<p>An additional [ESPIPE] error condition is added for sockets.</p>
<p>The DESCRIPTION is updated for alignment with IEEE&nbsp;Std&nbsp;1003.1j-2000 by specifying that <i>lseek</i>() results are
unspecified for typed memory objects.</p>
</blockquote>
<div class="box"><em>End of informative text.</em></div>
<hr>
<hr size="2" noshade>
<center><font size="2"><!--footer start-->
UNIX &reg; is a registered Trademark of The Open Group.<br>
POSIX &reg; is a registered Trademark of The IEEE.<br>
[ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href=
"../utilities/contents.html">XCU</a> | <a href="../functions/contents.html">XSH</a> | <a href="../xrat/contents.html">XRAT</a>
]</font></center>
<!--footer end-->
<hr size="2" noshade>
</body>
</html>