Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

125 lines
5.8KB

  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>open_memstream (The Red Hat newlib C Library)</title>
  7. <meta name="description" content="open_memstream (The Red Hat newlib C Library)">
  8. <meta name="keywords" content="open_memstream (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="perror.html#perror" rel="next" title="perror">
  17. <link href="mktemp.html#mktemp" rel="prev" title="mktemp">
  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="open_005fmemstream"></a>
  48. <div class="header">
  49. <p>
  50. Next: <a href="perror.html#perror" accesskey="n" rel="next">perror</a>, Previous: <a href="mktemp.html#mktemp" accesskey="p" rel="prev">mktemp</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="open_005fmemstream_002c-open_005fwmemstream_002d_002d_002dopen-a-write-stream-around-an-arbitrary_002dlength-string"></a>
  54. <h3 class="section">4.43 <code>open_memstream</code>, <code>open_wmemstream</code>&mdash;open a write stream around an arbitrary-length string</h3>
  55. <a name="index-open_005fmemstream"></a>
  56. <a name="index-open_005fwmemstream"></a>
  57. <p><strong>Synopsis</strong>
  58. </p><div class="example">
  59. <pre class="example">#include &lt;stdio.h&gt;
  60. FILE *open_memstream(char **restrict <var>buf</var>,
  61. size_t *restrict <var>size</var>);
  62. #include &lt;wchar.h&gt;
  63. FILE *open_wmemstream(wchar_t **restrict <var>buf</var>,
  64. size_t *restrict <var>size</var>);
  65. </pre></div>
  66. <p><strong>Description</strong><br>
  67. <code>open_memstream</code> creates a seekable, byte-oriented <code>FILE</code> stream that
  68. wraps an arbitrary-length buffer, created as if by <code>malloc</code>. The current
  69. contents of *<var>buf</var> are ignored; this implementation uses *<var>size</var>
  70. as a hint of the maximum size expected, but does not fail if the hint
  71. was wrong. The parameters <var>buf</var> and <var>size</var> are later stored
  72. through following any call to <code>fflush</code> or <code>fclose</code>, set to the
  73. current address and usable size of the allocated string; although
  74. after fflush, the pointer is only valid until another stream operation
  75. that results in a write. Behavior is undefined if the user alters
  76. either *<var>buf</var> or *<var>size</var> prior to <code>fclose</code>.
  77. </p>
  78. <p><code>open_wmemstream</code> is like <code>open_memstream</code> just with the associated
  79. stream being wide-oriented. The size set in <var>size</var> in subsequent
  80. operations is the number of wide characters.
  81. </p>
  82. <p>The stream is write-only, since the user can directly read *<var>buf</var>
  83. after a flush; see <code>fmemopen</code> for a way to wrap a string with a
  84. readable stream. The user is responsible for calling <code>free</code> on
  85. the final *<var>buf</var> after <code>fclose</code>.
  86. </p>
  87. <p>Any time the stream is flushed, a NUL byte is written at the current
  88. position (but is not counted in the buffer length), so that the string
  89. is always NUL-terminated after at most *<var>size</var> bytes (or wide characters
  90. in case of <code>open_wmemstream</code>). However, data previously written beyond
  91. the current stream offset is not lost, and the NUL value written during a
  92. flush is restored to its previous value when seeking elsewhere in the string.
  93. </p>
  94. <br>
  95. <p><strong>Returns</strong><br>
  96. The return value is an open FILE pointer on success. On error,
  97. <code>NULL</code> is returned, and <code>errno</code> will be set to EINVAL if <var>buf</var>
  98. or <var>size</var> is NULL, ENOMEM if memory could not be allocated, or
  99. EMFILE if too many streams are already open.
  100. </p>
  101. <br>
  102. <p><strong>Portability</strong><br>
  103. POSIX.1-2008
  104. </p>
  105. <p>Supporting OS subroutines required: <code>sbrk</code>.
  106. </p>
  107. <br>
  108. <hr>
  109. <div class="header">
  110. <p>
  111. Next: <a href="perror.html#perror" accesskey="n" rel="next">perror</a>, Previous: <a href="mktemp.html#mktemp" accesskey="p" rel="prev">mktemp</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>