1<html lang="en"> 2<head> 3<title>fseek - Untitled</title> 4<meta http-equiv="Content-Type" content="text/html"> 5<meta name="description" content="Untitled"> 6<meta name="generator" content="makeinfo 4.13"> 7<link title="Top" rel="start" href="index.html#Top"> 8<link rel="up" href="Stdio.html#Stdio" title="Stdio"> 9<link rel="prev" href="freopen.html#freopen" title="freopen"> 10<link rel="next" href="fsetpos.html#fsetpos" title="fsetpos"> 11<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage"> 12<meta http-equiv="Content-Style-Type" content="text/css"> 13<style type="text/css"><!-- 14 pre.display { font-family:inherit } 15 pre.format { font-family:inherit } 16 pre.smalldisplay { font-family:inherit; font-size:smaller } 17 pre.smallformat { font-family:inherit; font-size:smaller } 18 pre.smallexample { font-size:smaller } 19 pre.smalllisp { font-size:smaller } 20 span.sc { font-variant:small-caps } 21 span.roman { font-family:serif; font-weight:normal; } 22 span.sansserif { font-family:sans-serif; font-weight:normal; } 23--></style> 24<link rel="stylesheet" type="text/css" href="../cs.css"> 25</head> 26<body> 27<div class="node"> 28<a name="fseek"></a> 29<p> 30Next: <a rel="next" accesskey="n" href="fsetpos.html#fsetpos">fsetpos</a>, 31Previous: <a rel="previous" accesskey="p" href="freopen.html#freopen">freopen</a>, 32Up: <a rel="up" accesskey="u" href="Stdio.html#Stdio">Stdio</a> 33<hr> 34</div> 35 36<h3 class="section">4.26 <code>fseek</code>, <code>fseeko</code>—set file position</h3> 37 38<p><a name="index-fseek-198"></a><a name="index-fseeko-199"></a><a name="index-g_t_005ffseek_005fr-200"></a><a name="index-g_t_005ffseeko_005fr-201"></a><strong>Synopsis</strong> 39<pre class="example"> #include <stdio.h> 40 int fseek(FILE *<var>fp</var>, long <var>offset</var>, int <var>whence</var>) 41 int fseeko(FILE *<var>fp</var>, off_t <var>offset</var>, int <var>whence</var>) 42 int _fseek_r(struct _reent *<var>ptr</var>, FILE *<var>fp</var>, 43 long <var>offset</var>, int <var>whence</var>) 44 int _fseeko_r(struct _reent *<var>ptr</var>, FILE *<var>fp</var>, 45 off_t <var>offset</var>, int <var>whence</var>) 46 47</pre> 48 <p><strong>Description</strong><br> 49Objects of type <code>FILE</code> can have a “position” that records how much 50of the file your program has already read. Many of the <code>stdio</code> functions 51depend on this position, and many change it as a side effect. 52 53 <p>You can use <code>fseek</code>/<code>fseeko</code> to set the position for the file identified by 54<var>fp</var>. The value of <var>offset</var> determines the new position, in one 55of three ways selected by the value of <var>whence</var> (defined as macros 56in `<code>stdio.h</code>'): 57 58 <p><code>SEEK_SET</code>—<var>offset</var> is the absolute file position (an offset 59from the beginning of the file) desired. <var>offset</var> must be positive. 60 61 <p><code>SEEK_CUR</code>—<var>offset</var> is relative to the current file position. 62<var>offset</var> can meaningfully be either positive or negative. 63 64 <p><code>SEEK_END</code>—<var>offset</var> is relative to the current end of file. 65<var>offset</var> can meaningfully be either positive (to increase the size 66of the file) or negative. 67 68 <p>See <code>ftell</code>/<code>ftello</code> to determine the current file position. 69 70 <p><br> 71<strong>Returns</strong><br> 72<code>fseek</code>/<code>fseeko</code> return <code>0</code> when successful. On failure, the 73result is <code>EOF</code>. The reason for failure is indicated in <code>errno</code>: 74either <code>ESPIPE</code> (the stream identified by <var>fp</var> doesn't support 75repositioning) or <code>EINVAL</code> (invalid file position). 76 77 <p><br> 78<strong>Portability</strong><br> 79ANSI C requires <code>fseek</code>. 80 81 <p><code>fseeko</code> is defined by the Single Unix specification. 82 83 <p>Supporting OS subroutines required: <code>close</code>, <code>fstat</code>, <code>isatty</code>, 84<code>lseek</code>, <code>read</code>, <code>sbrk</code>, <code>write</code>. 85 86 <p><br> 87 88 </body></html> 89 90