選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

130 行
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>fread (The Red Hat newlib C Library)</title>
  7. <meta name="description" content="fread (The Red Hat newlib C Library)">
  8. <meta name="keywords" content="fread (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="freopen.html#freopen" rel="next" title="freopen">
  17. <link href="fputws.html#fputws" rel="prev" title="fputws">
  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="fread"></a>
  48. <div class="header">
  49. <p>
  50. Next: <a href="freopen.html#freopen" accesskey="n" rel="next">freopen</a>, Previous: <a href="fputws.html#fputws" accesskey="p" rel="prev">fputws</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="fread_002c-fread_005funlocked_002d_002d_002dread-array-elements-from-a-file"></a>
  54. <h3 class="section">4.24 <code>fread</code>, <code>fread_unlocked</code>&mdash;read array elements from a file</h3>
  55. <a name="index-fread"></a>
  56. <a name="index-fread_005funlocked"></a>
  57. <a name="index-_005ffread_005fr"></a>
  58. <a name="index-_005ffread_005funlocked_005fr"></a>
  59. <p><strong>Synopsis</strong>
  60. </p><div class="example">
  61. <pre class="example">#include &lt;stdio.h&gt;
  62. size_t fread(void *restrict <var>buf</var>, size_t <var>size</var>, size_t <var>count</var>,
  63. FILE *restrict <var>fp</var>);
  64. #define _BSD_SOURCE
  65. #include &lt;stdio.h&gt;
  66. size_t fread_unlocked(void *restrict <var>buf</var>, size_t <var>size</var>, size_t <var>count</var>,
  67. FILE *restrict <var>fp</var>);
  68. #include &lt;stdio.h&gt;
  69. size_t _fread_r(struct _reent *<var>ptr</var>, void *restrict <var>buf</var>,
  70. size_t <var>size</var>, size_t <var>count</var>, FILE *restrict <var>fp</var>);
  71. #include &lt;stdio.h&gt;
  72. size_t _fread_unlocked_r(struct _reent *<var>ptr</var>, void *restrict <var>buf</var>,
  73. size_t <var>size</var>, size_t <var>count</var>, FILE *restrict <var>fp</var>);
  74. </pre></div>
  75. <p><strong>Description</strong><br>
  76. <code>fread</code> attempts to copy, from the file or stream identified by
  77. <var>fp</var>, <var>count</var> elements (each of size <var>size</var>) into memory,
  78. starting at <var>buf</var>. <code>fread</code> may copy fewer elements than
  79. <var>count</var> if an error, or end of file, intervenes.
  80. </p>
  81. <p><code>fread</code> also advances the file position indicator (if any) for
  82. <var>fp</var> by the number of <em>characters</em> actually read.
  83. </p>
  84. <p><code>fread_unlocked</code> is a non-thread-safe version of <code>fread</code>.
  85. <code>fread_unlocked</code> may only safely be used within a scope
  86. protected by flockfile() (or ftrylockfile()) and funlockfile(). This
  87. function may safely be used in a multi-threaded program if and only
  88. if they are called while the invoking thread owns the (FILE *)
  89. object, as is the case after a successful call to the flockfile() or
  90. ftrylockfile() functions. If threads are disabled, then
  91. <code>fread_unlocked</code> is equivalent to <code>fread</code>.
  92. </p>
  93. <p><code>_fread_r</code> and <code>_fread_unlocked_r</code> are simply reentrant versions of the
  94. above that take an additional reentrant structure pointer argument: <var>ptr</var>.
  95. </p>
  96. <br>
  97. <p><strong>Returns</strong><br>
  98. The result of <code>fread</code> is the number of elements it succeeded in
  99. reading.
  100. </p>
  101. <br>
  102. <p><strong>Portability</strong><br>
  103. ANSI C requires <code>fread</code>.
  104. </p>
  105. <p><code>fread_unlocked</code> is a BSD extension also provided by GNU libc.
  106. </p>
  107. <p>Supporting OS subroutines required: <code>close</code>, <code>fstat</code>, <code>isatty</code>,
  108. <code>lseek</code>, <code>read</code>, <code>sbrk</code>, <code>write</code>.
  109. </p>
  110. <br>
  111. <hr>
  112. <div class="header">
  113. <p>
  114. Next: <a href="freopen.html#freopen" accesskey="n" rel="next">freopen</a>, Previous: <a href="fputws.html#fputws" accesskey="p" rel="prev">fputws</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>
  115. </div>
  116. </body>
  117. </html>