Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

124 lines
5.7KB

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ -->
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  6. <title>fseek (The Red Hat newlib C Library)</title>
  7. <meta name="description" content="fseek (The Red Hat newlib C Library)">
  8. <meta name="keywords" content="fseek (The Red Hat newlib C Library)">
  9. <meta name="resource-type" content="document">
  10. <meta name="distribution" content="global">
  11. <meta name="Generator" content="makeinfo">
  12. <link href="index.html#Top" rel="start" title="Top">
  13. <link href="Document-Index.html#Document-Index" rel="index" title="Document Index">
  14. <link href="Document-Index.html#SEC_Contents" rel="contents" title="Table of Contents">
  15. <link href="Stdio.html#Stdio" rel="up" title="Stdio">
  16. <link href="_005f_005ffsetlocking.html#g_t_005f_005ffsetlocking" rel="next" title="__fsetlocking">
  17. <link href="freopen.html#freopen" rel="prev" title="freopen">
  18. <style type="text/css">
  19. <!--
  20. a.summary-letter {text-decoration: none}
  21. blockquote.indentedblock {margin-right: 0em}
  22. blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
  23. blockquote.smallquotation {font-size: smaller}
  24. div.display {margin-left: 3.2em}
  25. div.example {margin-left: 3.2em}
  26. div.lisp {margin-left: 3.2em}
  27. div.smalldisplay {margin-left: 3.2em}
  28. div.smallexample {margin-left: 3.2em}
  29. div.smalllisp {margin-left: 3.2em}
  30. kbd {font-style: oblique}
  31. pre.display {font-family: inherit}
  32. pre.format {font-family: inherit}
  33. pre.menu-comment {font-family: serif}
  34. pre.menu-preformatted {font-family: serif}
  35. pre.smalldisplay {font-family: inherit; font-size: smaller}
  36. pre.smallexample {font-size: smaller}
  37. pre.smallformat {font-family: inherit; font-size: smaller}
  38. pre.smalllisp {font-size: smaller}
  39. span.nolinebreak {white-space: nowrap}
  40. span.roman {font-family: initial; font-weight: normal}
  41. span.sansserif {font-family: sans-serif; font-weight: normal}
  42. ul.no-bullet {list-style: none}
  43. -->
  44. </style>
  45. </head>
  46. <body lang="en">
  47. <a name="fseek"></a>
  48. <div class="header">
  49. <p>
  50. Next: <a href="_005f_005ffsetlocking.html#g_t_005f_005ffsetlocking" accesskey="n" rel="next">__fsetlocking</a>, Previous: <a href="freopen.html#freopen" accesskey="p" rel="prev">freopen</a>, Up: <a href="Stdio.html#Stdio" accesskey="u" rel="up">Stdio</a> &nbsp; [<a href="Document-Index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Document-Index.html#Document-Index" title="Index" rel="index">Index</a>]</p>
  51. </div>
  52. <hr>
  53. <a name="fseek_002c-fseeko_002d_002d_002dset-file-position"></a>
  54. <h3 class="section">4.26 <code>fseek</code>, <code>fseeko</code>&mdash;set file position</h3>
  55. <a name="index-fseek"></a>
  56. <a name="index-fseeko"></a>
  57. <a name="index-_005ffseek_005fr"></a>
  58. <a name="index-_005ffseeko_005fr"></a>
  59. <p><strong>Synopsis</strong>
  60. </p><div class="example">
  61. <pre class="example">#include &lt;stdio.h&gt;
  62. int fseek(FILE *<var>fp</var>, long <var>offset</var>, int <var>whence</var>);
  63. int fseeko(FILE *<var>fp</var>, off_t <var>offset</var>, int <var>whence</var>);
  64. int _fseek_r(struct _reent *<var>ptr</var>, FILE *<var>fp</var>,
  65. long <var>offset</var>, int <var>whence</var>);
  66. int _fseeko_r(struct _reent *<var>ptr</var>, FILE *<var>fp</var>,
  67. off_t <var>offset</var>, int <var>whence</var>);
  68. </pre></div>
  69. <p><strong>Description</strong><br>
  70. Objects of type <code>FILE</code> can have a &ldquo;position&rdquo; that records how much
  71. of the file your program has already read. Many of the <code>stdio</code> functions
  72. depend on this position, and many change it as a side effect.
  73. </p>
  74. <p>You can use <code>fseek</code>/<code>fseeko</code> to set the position for the file identified by
  75. <var>fp</var>. The value of <var>offset</var> determines the new position, in one
  76. of three ways selected by the value of <var>whence</var> (defined as macros
  77. in &lsquo;<code>stdio.h</code>&rsquo;):
  78. </p>
  79. <p><code>SEEK_SET</code>&mdash;<var>offset</var> is the absolute file position (an offset
  80. from the beginning of the file) desired. <var>offset</var> must be positive.
  81. </p>
  82. <p><code>SEEK_CUR</code>&mdash;<var>offset</var> is relative to the current file position.
  83. <var>offset</var> can meaningfully be either positive or negative.
  84. </p>
  85. <p><code>SEEK_END</code>&mdash;<var>offset</var> is relative to the current end of file.
  86. <var>offset</var> can meaningfully be either positive (to increase the size
  87. of the file) or negative.
  88. </p>
  89. <p>See <code>ftell</code>/<code>ftello</code> to determine the current file position.
  90. </p>
  91. <br>
  92. <p><strong>Returns</strong><br>
  93. <code>fseek</code>/<code>fseeko</code> return <code>0</code> when successful. On failure, the
  94. result is <code>EOF</code>. The reason for failure is indicated in <code>errno</code>:
  95. either <code>ESPIPE</code> (the stream identified by <var>fp</var> doesn&rsquo;t support
  96. repositioning) or <code>EINVAL</code> (invalid file position).
  97. </p>
  98. <br>
  99. <p><strong>Portability</strong><br>
  100. ANSI C requires <code>fseek</code>.
  101. </p>
  102. <p><code>fseeko</code> is defined by the Single Unix specification.
  103. </p>
  104. <p>Supporting OS subroutines required: <code>close</code>, <code>fstat</code>, <code>isatty</code>,
  105. <code>lseek</code>, <code>read</code>, <code>sbrk</code>, <code>write</code>.
  106. </p>
  107. <br>
  108. <hr>
  109. <div class="header">
  110. <p>
  111. Next: <a href="_005f_005ffsetlocking.html#g_t_005f_005ffsetlocking" accesskey="n" rel="next">__fsetlocking</a>, Previous: <a href="freopen.html#freopen" accesskey="p" rel="prev">freopen</a>, Up: <a href="Stdio.html#Stdio" accesskey="u" rel="up">Stdio</a> &nbsp; [<a href="Document-Index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Document-Index.html#Document-Index" title="Index" rel="index">Index</a>]</p>
  112. </div>
  113. </body>
  114. </html>