您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

fmemopen.html 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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>fmemopen (The Red Hat newlib C Library)</title>
  7. <meta name="description" content="fmemopen (The Red Hat newlib C Library)">
  8. <meta name="keywords" content="fmemopen (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="fopen.html#fopen" rel="next" title="fopen">
  17. <link href="fileno.html#fileno" rel="prev" title="fileno">
  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="fmemopen"></a>
  48. <div class="header">
  49. <p>
  50. Next: <a href="fopen.html#fopen" accesskey="n" rel="next">fopen</a>, Previous: <a href="fileno.html#fileno" accesskey="p" rel="prev">fileno</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="fmemopen_002d_002d_002dopen-a-stream-around-a-fixed_002dlength-string"></a>
  54. <h3 class="section">4.16 <code>fmemopen</code>&mdash;open a stream around a fixed-length string</h3>
  55. <a name="index-fmemopen"></a>
  56. <p><strong>Synopsis</strong>
  57. </p><div class="example">
  58. <pre class="example">#include &lt;stdio.h&gt;
  59. FILE *fmemopen(void *restrict <var>buf</var>, size_t <var>size</var>,
  60. const char *restrict <var>mode</var>);
  61. </pre></div>
  62. <p><strong>Description</strong><br>
  63. <code>fmemopen</code> creates a seekable <code>FILE</code> stream that wraps a
  64. fixed-length buffer of <var>size</var> bytes starting at <var>buf</var>. The stream
  65. is opened with <var>mode</var> treated as in <code>fopen</code>, where append mode
  66. starts writing at the first NUL byte. If <var>buf</var> is NULL, then
  67. <var>size</var> bytes are automatically provided as if by <code>malloc</code>, with
  68. the initial size of 0, and <var>mode</var> must contain <code>+</code> so that data
  69. can be read after it is written.
  70. </p>
  71. <p>The stream maintains a current position, which moves according to
  72. bytes read or written, and which can be one past the end of the array.
  73. The stream also maintains a current file size, which is never greater
  74. than <var>size</var>. If <var>mode</var> starts with <code>r</code>, the position starts at
  75. <code>0</code>, and file size starts at <var>size</var> if <var>buf</var> was provided. If
  76. <var>mode</var> starts with <code>w</code>, the position and file size start at <code>0</code>,
  77. and if <var>buf</var> was provided, the first byte is set to NUL. If
  78. <var>mode</var> starts with <code>a</code>, the position and file size start at the
  79. location of the first NUL byte, or else <var>size</var> if <var>buf</var> was
  80. provided.
  81. </p>
  82. <p>When reading, NUL bytes have no significance, and reads cannot exceed
  83. the current file size. When writing, the file size can increase up to
  84. <var>size</var> as needed, and NUL bytes may be embedded in the stream (see
  85. <code>open_memstream</code> for an alternative that automatically enlarges the
  86. buffer). When the stream is flushed or closed after a write that
  87. changed the file size, a NUL byte is written at the current position
  88. if there is still room; if the stream is not also open for reading, a
  89. NUL byte is additionally written at the last byte of <var>buf</var> when the
  90. stream has exceeded <var>size</var>, so that a write-only <var>buf</var> is always
  91. NUL-terminated when the stream is flushed or closed (and the initial
  92. <var>size</var> should take this into account). It is not possible to seek
  93. outside the bounds of <var>size</var>. A NUL byte written during a flush is
  94. restored to its previous value when seeking elsewhere in the string.
  95. </p>
  96. <br>
  97. <p><strong>Returns</strong><br>
  98. The return value is an open FILE pointer on success. On error,
  99. <code>NULL</code> is returned, and <code>errno</code> will be set to EINVAL if <var>size</var>
  100. is zero or <var>mode</var> is invalid, ENOMEM if <var>buf</var> was NULL and memory
  101. could not be allocated, or EMFILE if too many streams are already
  102. open.
  103. </p>
  104. <br>
  105. <p><strong>Portability</strong><br>
  106. This function is being added to POSIX 200x, but is not in POSIX 2001.
  107. </p>
  108. <p>Supporting OS subroutines required: <code>sbrk</code>.
  109. </p>
  110. <br>
  111. <hr>
  112. <div class="header">
  113. <p>
  114. Next: <a href="fopen.html#fopen" accesskey="n" rel="next">fopen</a>, Previous: <a href="fileno.html#fileno" accesskey="p" rel="prev">fileno</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>