OSDN Git Service

(split) LDP v3.30, v3.31 の定型的な変更内容を反映。
[linuxjm/LDP_man-pages.git] / draft / man3 / fmemopen.3
1 .\" Copyright 2005 walter harms (walter.harms@informatik.uni-oldenburg.de),
2 .\" and Copyright 2005 Michael Kerrisk <mtk.manpages@gmail.com>
3 .\" Distributed under the GPL.
4 .\" 2008-12-04, Petr Baudis <pasky@suse.cz>: Document open_wmemstream()
5 .\"
6 .\" Japanese Version Copyright (c) 2005, 2006 Akihiro MOTOKI
7 .\"                     all rights reserved.
8 .\" Translated 2005-12-26, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
9 .\" Updated 2006-01-20, Akihiro MOTOKI
10 .\" Updated 2006-07-20, Akihiro MOTOKI
11 .\" Updated 2008-11-08, Akihiro MOTOKI, LDP v3.13
12 .\" Updated 2010-04-18, Akihiro MOTOKI, LDP v3.24
13 .\"
14 .TH FMEMOPEN 3 2010-09-15 "GNU" "Linux Programmer's Manual"
15 .\"O .SH NAME
16 .SH Ì¾Á°
17 .\"O fmemopen, open_memstream, open_wmemstream \-  open memory as stream
18 fmemopen, open_memstream, open_wmemstream \-  ¥á¥â¥ê¤ò¥¹¥È¥ê¡¼¥à¤È¤·¤Æ¥ª¡¼¥×¥ó¤¹¤ë
19 .\"O .SH SYNOPSIS
20 .SH ½ñ¼°
21 .nf
22 .B #include <stdio.h>
23
24 .BI "FILE *fmemopen(void *"buf ", size_t "size ", const char *" mode ");"
25
26 .BI "FILE *open_memstream(char **" ptr ", size_t *" sizeloc );
27
28 .B #include <wchar.h>
29
30 .BI "FILE *open_wmemstream(wchar_t **" ptr ", size_t *" sizeloc );
31 .fi
32 .fi
33 .sp
34 .in -4n
35 .\"O Feature Test Macro Requirements for glibc (see
36 .\"O .BR feature_test_macros (7)):
37 glibc ¸þ¤±¤Îµ¡Ç½¸¡ºº¥Þ¥¯¥í¤ÎÍ×·ï
38 .RB ( feature_test_macros (7)
39 »²¾È):
40 .in
41 .sp
42 .BR fmemopen (),
43 .BR open_memstream (),
44 .BR open_wmemstream ():
45 .PD 0
46 .ad l
47 .RS 4
48 .TP 4
49 .\"O Since glibc 2.10:
50 glibc 2.10 °Ê¹ß:
51 _XOPEN_SOURCE\ >=\ 700 || _POSIX_C_SOURCE\ >=\ 200809L
52 .TP
53 .\"O Before glibc 2.10:
54 glibc 2.10 ¤è¤êÁ°:
55 _GNU_SOURCE
56 .RE
57 .ad
58 .PD
59 .\"O .SH DESCRIPTION
60 .SH ÀâÌÀ
61 .\"O The
62 .\"O .BR fmemopen ()
63 .\"O function opens a stream that permits the access specified by
64 .\"O .IR mode .
65 .\"O The stream allows I/O to be performed on the string or memory buffer
66 .\"O pointed to by
67 .\"O .IR buf .
68 .\"O This buffer must be at least
69 .\"O .I size
70 .\"O bytes long.
71 .BR fmemopen ()
72 ´Ø¿ô¤Ï¡¢¥¹¥È¥ê¡¼¥à¤ò¥ª¡¼¥×¥ó¤·¡¢¤½¤Î¥¹¥È¥ê¡¼¥à¤Ë
73 .I mode
74 ¤Ç»ØÄꤵ¤ì¤¿¥¢¥¯¥»¥¹µö²Ä¤òÀßÄꤹ¤ë¡£
75 ¤½¤Î¥¹¥È¥ê¡¼¥à¤òÄ̤¸¤Æ¡¢
76 .I buf
77 ¤Ç»ØÄꤵ¤ì¤¿Ê¸»úÎó¤ä¥á¥â¥ê¥Ð¥Ã¥Õ¥¡¤Ø¤ÎÆɤ߽ñ¤­¤¬¤Ç¤­¤ë¡£
78 ¤³¤Î¥Ð¥Ã¥Õ¥¡¤Ï¾¯¤Ê¤¯¤È¤â
79 .I size
80 ¥Ð¥¤¥È¤ÎŤµ¤Ç¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
81 .PP
82 .\"O The argument
83 .\"O .I mode
84 .\"O is the same as for
85 .\"O .BR fopen (3).
86 .\"O If
87 .\"O .I mode
88 .\"O specifies an append mode, then the initial file position is set to
89 .\"O the location of the first null byte (\(aq\\0\(aq) in the buffer;
90 .\"O otherwise the initial file position is set to the start of the buffer.
91 °ú¤­¿ô
92 .I mode
93 ¤Ï
94 .BR fopen (3)
95 ¤Î¾ì¹ç¤ÈƱ¤¸¤Ç¤¢¤ë¡£
96 .I mode
97 ¤ÇÄɵ­¥â¡¼¥É (append mode) ¤¬»ØÄꤵ¤ì¤¿¾ì¹ç¡¢¥Õ¥¡¥¤¥ë°ÌÃ֤νé´üÃͤÏ
98 ¥Ð¥Ã¥Õ¥¡Ãæ¤ÎºÇ½é¤Î NULL ¥Ð¥¤¥È (\(aq\\0\(aq) ¤Î°ÌÃÖ¤ËÀßÄꤵ¤ì¤ë¡£
99 ¤½¤ì°Ê³°¤Î¾ì¹ç¤Ï¡¢¥Õ¥¡¥¤¥ë°ÌÃ֤νé´üÃͤϥХåե¡¤ÎÀèƬ¤Ë¤Ê¤ë¡£
100 .\"O Since glibc 2.9,
101 .\"O the letter 'b' may be specified as the second character in
102 .\"O .IR mode .
103 .\"O This provides "binary" mode:
104 .\"O writes don't implicitly add a terminating null byte, and
105 .\"O .BR fseek (3)
106 .\"O .B SEEK_END
107 .\"O is relative to the end of the buffer (i.e., the value specified by the
108 .\"O .I size
109 .\"O argument), rather than the current string length.
110 glibc 2.9 °Ê¹ß¤Ç¤Ï¡¢Ê¸»ú 'b' ¤ò
111 .I mode
112 ¤ÎÆóÈÖÌܤÎʸ»ú¤È¤·¤Æ»ØÄꤹ¤ë¤³¤È¤¬¤Ç¤­¤ë¡£
113 ¤³¤Îʸ»ú¤Ï¡Ö¥Ð¥¤¥Ê¥ê¡×¥â¡¼¥É¤ò»ØÄꤹ¤ë¤â¤Î¤Ç¤¢¤ë¡£
114 ¤³¤Î¥â¡¼¥É¤Ç¤Ï¡¢½ñ¤­¹þ¤ß»þ¤Ëʸ»úÎó½ªÃ¼¤Î¥Ì¥ë¥Ð¥¤¥È¤¬ÌۤäÆÄɲÃ
115 ¤µ¤ì¤ë¤³¤È¤Ï¤Ê¤¤¡£¤Þ¤¿¡¢
116 .BR fseek (3)
117 .B SEEK_END
118 ¤Ï¡¢Ê¸»úÎó¤ÎŤµ¤«¤é¤ÎÁêÂÐÃͤǤϤʤ¯¡¢¥Ð¥Ã¥Õ¥¡¤ÎËöÈø
119 .RI ( size
120 ¤Ç»ØÄꤷ¤¿ÃÍ) ¤«¤é¤ÎÁêÂÐÃͤȤʤ롣
121 .PP
122 .\"O When a stream that has been opened for writing is flushed
123 .\"O .RB ( fflush (3))
124 .\"O or closed
125 .\"O .RB ( fclose (3)),
126 .\"O a null byte is written at the end of the buffer if there is space.
127 .\"O The caller should ensure that an extra byte is available in the
128 .\"O buffer
129 .\"O (and that
130 .\"O .I size
131 .\"O counts that byte)
132 .\"O to allow for this.
133 ½ñ¤­¹þ¤ßÍѤ˥ª¡¼¥×¥ó¤µ¤ì¤¿¥¹¥È¥ê¡¼¥à¤ò¥Õ¥é¥Ã¥·¥å
134 .RB ( fflush (3))
135 ¤ä¥¯¥í¡¼¥º
136 .RB ( fclose (3))
137 ¤·¤¿»þ¤Ë¡¢
138 (¥Ð¥Ã¥Õ¥¡¤Ë¶õ¤­¤¬¤¢¤ì¤Ð) NULL ¥Ð¥¤¥È¤¬¥Ð¥Ã¥Õ¥¡¤ÎËöÈø¤Ë½ñ¤­¹þ¤Þ¤ì¤ë¡£
139 ¤³¤Î¤è¤¦¤Ë¤¹¤ë¤¿¤á¤Ë¤Ï¡¢¸Æ¤Ó½Ð¤·¸µ¤Ï
140 ¥Ð¥Ã¥Õ¥¡¤Ë 1¥Ð¥¤¥È;͵¤òºî¤ë
141 .RI ( size
142 ¤Ë¤³¤Î 1¥Ð¥¤¥È¤ò´Þ¤á¤¿Ãͤò»ØÄꤹ¤ë) É¬Íפ¬¤¢¤ë¡£
143
144 .\"O Attempts to write more than
145 .\"O .I size
146 .\"O bytes to the buffer result in an error.
147 ¥Ð¥Ã¥Õ¥¡¤Ë
148 .I size
149 ¥Ð¥¤¥È¤è¤ê¤¿¤¯¤µ¤ó½ñ¤­¹þ¤â¤¦¤È¤·¤¿¾ì¹ç¤Ë¤Ï¡¢¥¨¥é¡¼¤È¤Ê¤ë¡£
150 .\"O (By default, such errors will only be visible when the
151 .\"O .I stdio
152 .\"O buffer is flushed.
153 .\"O Disabling buffering with
154 .\"O .I setbuf(fp,\ NULL)
155 .\"O may be useful to detect errors at the time of an output operation.
156 .\"O Alternatively, the caller can explicitly set
157 .\"O .I buf
158 .\"O as the stdio stream buffer, at the same time informing stdio
159 .\"O of the buffer's size, using
160 .\"O .IR "setbuffer(fp, buf, size)" .)
161 (¥Ç¥Õ¥©¥ë¥È¤Ç¤Ï¡¢¤³¤Î¤è¤¦¤Ê¥¨¥é¡¼¤¬¸«¤¨¤ë¤Î¤Ï
162 .I stdio
163 ¥Ð¥Ã¥Õ¥¡¤¬¥Õ¥é¥Ã¥·¥å¤µ¤ì¤¿»þ¤À¤±¤Ç¤¢¤ë¡£
164 .I setbuf(fp,\ NULL)
165 ¤ò»È¤Ã¤Æ¥Ð¥Ã¥Õ¥¡¥ê¥ó¥°¤ò̵¸ú¤Ë¤¹¤ëÊýË¡¤Ï¡¢
166 ½ÐÎÏÁàºî¤ò¹Ô¤Ã¤¿»þÅÀ¤Ç¥¨¥é¡¼¤ò¸¡½Ð¤¹¤ë¤Î¤ËÌòΩ¤Ä¡£
167 Ê̤ÎÊýË¡¤È¤·¤Æ¤Ï¡¢
168 .IR "setbuffer(fp, buf, size)"
169 ¤ò»È¤Ã¤Æ¡¢¸Æ¤Ó½Ð¤·Â¦¤¬ÌÀ¼¨Åª¤Ë
170 stdio ¥¹¥È¥ê¡¼¥à¥Ð¥Ã¥Õ¥¡¤È¤·¤Æ
171 .I buf
172 ¤ò»ØÄꤷ¡¢¥Ð¥Ã¥Õ¥¡¤Î»ØÄê»þ¤Ë¥Ð¥Ã¥Õ¥¡¤Î¥µ¥¤¥º¤ò
173 stdio ¤Ë¶µ¤¨¤ëÊýË¡¤¬¤¢¤ë¡£)
174 .\" See http://sourceware.org/bugzilla/show_bug.cgi?id=1995
175 .\" and
176 .\" http://sources.redhat.com/ml/libc-alpha/2006-04/msg00064.html
177 .PP
178 .\"O In a stream opened for reading,
179 .\"O null bytes (\(aq\\0\(aq) in the buffer do not cause read
180 .\"O operations to return an end-of-file indication.
181 .\"O A read from the buffer will only indicate end-of-file
182 .\"O when the file pointer advances
183 .\"O .I size
184 .\"O bytes past the start of the buffer.
185 Æɤ߽Ф·ÍѤ˥ª¡¼¥×¥ó¤µ¤ì¤¿¥¹¥È¥ê¡¼¥à¤Ç¤Ï¡¢
186 ¥Ð¥Ã¥Õ¥¡Æâ¤Ë NULL ¥Ð¥¤¥È (\(aq\\0\(aq) ¤¬¤¢¤Ã¤Æ¤â
187 Æɤ߽Ф·Áàºî¤¬¥Õ¥¡¥¤¥ëËöÈø (end-of-file) ¤òÊÖ¤¹¤³¤È¤Ï¤Ê¤¤¡£
188 ¥Ð¥Ã¥Õ¥¡¤«¤é¤ÎÆɤ߽Ф·¤Ç¥Õ¥¡¥¤¥ëËöÈø¤¬ÊÖ¤ë¤Î¤Ï¡¢
189 ¥Õ¥¡¥¤¥ë¥Ý¥¤¥ó¥¿¤¬¥Ð¥Ã¥Õ¥¡¤ÎÀèƬ¤«¤é
190 .I size
191 ¥Ð¥¤¥È¤ò±Û¤¨¤ÆÀè¤Ë¿Ê¤â¤¦¤È¤·¤¿¾ì¹ç¤À¤±¤Ç¤¢¤ë¡£
192 .PP
193 .\"O If
194 .\"O .I buf
195 .\"O is specified as NULL, then
196 .\"O .BR fmemopen ()
197 .\"O dynamically allocates a buffer
198 .\"O .I size
199 .\"O bytes long.
200 .I buf
201 ¤Ë NULL ¤¬»ØÄꤵ¤ì¤¿¾ì¹ç¡¢
202 .BR fmemopen ()
203 ¤ÏưŪ¤Ë
204 .I size
205 ¥Ð¥¤¥È¤ÎŤµ¤Î¥Ð¥Ã¥Õ¥¡¤ò³ÎÊݤ¹¤ë¡£
206 .\"O This is useful for an application that wants to write data to
207 .\"O a temporary buffer and then read it back again.
208 .\"O The buffer is automatically freed when the stream is closed.
209 .\"O Note that the caller has no way to obtain a pointer to the
210 .\"O temporary buffer allocated by this call (but see
211 .\"O .BR open_memstream ()
212 .\"O below).
213 ¤³¤ÎÊýË¡¤Ï¡¢°ì»þ¥Ð¥Ã¥Õ¥¡¤Ë¥Ç¡¼¥¿¤Î½ñ¤­¹þ¤ß¤ò¹Ô¤Ã¤Æ¤«¤é¡¢
214 ¤½¤ÎÆâÍƤòºÆÅÙÆɤ߽Ф¹¤è¤¦¤Ê¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤ÇÍ­ÍѤǤ¢¤ë¡£
215 ¤³¤Î¥Ð¥Ã¥Õ¥¡¤Ï¥¹¥È¥ê¡¼¥à¤¬¥¯¥í¡¼¥º¤µ¤ì¤ë¤È¤­¤Ë¼«Æ°Åª¤Ë²òÊü¤µ¤ì¤ë¡£
216 ¸Æ¤Ó½Ð¤·¸µ¤«¤é¤Ï¤³¤Î´Ø¿ô¤¬³ä¤êÅö¤Æ¤¿°ì»þ¥Ð¥Ã¥Õ¥¡¤Ø¤Î¥Ý¥¤¥ó¥¿Ãͤò
217 ÃΤëÊýË¡¤Ï¸ºß¤·¤Ê¤¤ÅÀ¤ËÃí°Õ (²¼µ­¤Î
218 .BR open_memstream ()
219 ¤â»²¾È)¡£
220
221 .\"O The
222 .\"O .BR open_memstream ()
223 .\"O function opens a stream for writing to a buffer.
224 .\"O The buffer
225 .\"O is dynamically allocated (as with
226 .\"O .BR malloc (3)),
227 .\"O and automatically grows as required.
228 .\"O After closing the stream, the caller should
229 .\"O .BR free (3)
230 .\"O this buffer.
231 .BR open_memstream ()
232 ´Ø¿ô¤Ï¡¢¥Ð¥Ã¥Õ¥¡¤Ø¤Î½ñ¤­¹þ¤ßÍѤ˥¹¥È¥ê¡¼¥à¤ò¥ª¡¼¥×¥ó¤¹¤ë¡£
233 ¥Ð¥Ã¥Õ¥¡¤Ï
234 .RB ( malloc (3)
235 ¤ò»È¤Ã¤Æ) Æ°Åª¤Ë³ä¤êÅö¤Æ¤é¤ì¡¢É¬Íפ˱þ¤¸¤Æ¼«Æ°Åª¤Ë¿­Ä¹¤¹¤ë¡£
236 ¥¹¥È¥ê¡¼¥à¤ò¥¯¥í¡¼¥º¤·¤¿¸å¤Ç¡¢¸Æ¤Ó½Ð¤·¸µ¤Ï¤³¤Î¥Ð¥Ã¥Õ¥¡¤ò
237 .BR free (3)
238 ¤¹¤Ù¤­¤Ç¤¢¤ë¡£
239
240 .\"O When the stream is closed
241 .\"O .RB ( fclose (3))
242 .\"O or flushed
243 .\"O .RB ( fflush (3)),
244 .\"O the locations pointed to by
245 .\"O .I ptr
246 .\"O and
247 .\"O .I sizeloc
248 .\"O are updated to contain, respectively, a pointer to the buffer and the
249 .\"O current size of the buffer.
250 .\"O These values remain valid only as long as the caller
251 .\"O performs no further output on the stream.
252 .\"O If further output is performed, then the stream
253 .\"O must again be flushed before trying to access these variables.
254 ¤³¤Î¥¹¥È¥ê¡¼¥à¤¬
255 ¥¯¥í¡¼¥º
256 .RB ( fclose (3))
257 ¤µ¤ì¤¿¤ê¥Õ¥é¥Ã¥·¥å
258 .RB ( fflush (3))
259 ¤µ¤ì¤¿»þ¤Ë¡¢
260 .I ptr
261 ¤È
262 .I sizeloc
263 ¤ÎÃͤϤ½¤ì¤¾¤ì¥Ð¥Ã¥Õ¥¡¤Ø¤Î¥Ý¥¤¥ó¥¿¤È¤½¤Î¥µ¥¤¥º¤Ë¹¹¿·¤µ¤ì¤ë¡£
264 ¤³¤ì¤é¤ÎÃͤϡ¢¸Æ¤Ó½Ð¤·¸µ¤¬¤½¤Î¥¹¥È¥ê¡¼¥à¤Ë¿·¤¿¤Ê½ñ¤­¹þ¤ß¤ò
265 ¹Ô¤ï¤Ê¤¤¾ì¹ç¤Ë¸Â¤êÍ­¸ú¤Ç¤¢¤ë¡£
266 ¥¹¥È¥ê¡¼¥à¤Ë½ñ¤­¹þ¤ß¤ò¹Ô¤Ã¤¿ºÝ¤Ë¤Ï¡¢¤³¤ì¤é¤ÎÊÑ¿ô¤ò»²¾È¤¹¤ëÁ°¤Ë
267 ¥¹¥È¥ê¡¼¥à¤òºÆÅÙ¥Õ¥é¥Ã¥·¥å¤·¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
268
269 .\"O A null byte is maintained at the end of the buffer.
270 .\"O This byte is
271 .\"O .I not
272 .\"O included in the size value stored at
273 .\"O .IR sizeloc .
274 ¥Ð¥Ã¥Õ¥¡ËöÈø¤Î NULL ¥Ð¥¤¥È¤ÏÊÝ»ý¤µ¤ì¤ë¡£
275 ¤³¤Î NULL ¥Ð¥¤¥È¤Ï
276 .I sizeloc
277 ¤Ë³ÊǼ¤µ¤ì¤ë¥µ¥¤¥º¤Ë¤Ï¡Ö´Þ¤Þ¤ì¤Ê¤¤¡×¡£
278
279 .\"O The stream's file position can be changed with
280 .\"O .BR fseek (3)
281 .\"O or
282 .\"O .BR fseeko (3).
283 .\"O Moving the file position past the end
284 .\"O of the data already written fills the intervening space with
285 .\"O zeros.
286 ¥¹¥È¥ê¡¼¥à¤Î¥Õ¥¡¥¤¥ë°ÌÃÖ¤Ï
287 .BR fseek (3)
288 ¤ä
289 .BR fseeko (3)
290 ¤ÇÊѹ¹¤Ç¤­¤ë¡£
291 ¤¹¤Ç¤Ë¥Ç¡¼¥¿¤¬½ñ¤­¹þ¤Þ¤ì¤¿Îΰè¤ÎËöÈø¤è¤êÀè¤Ë¥Õ¥¡¥¤¥ë°ÌÃÖ¤òÆ°¤«¤¹¤È¡¢
292 ¤½¤Î´Ö¤ÎÎΰè¤Ï 0 ¤ÇËä¤á¤é¤ì¤ë¡£
293
294 .\"O The
295 .\"O .BR open_wmemstream ()
296 .\"O is similar to
297 .\"O .BR open_memstream (),
298 .\"O but operates on wide characters instead of bytes.
299 .BR open_wmemstream ()
300 ¤Ï
301 .BR open_memstream ()
302 ¤ÈƱÍͤÀ¤¬¡¢¥Ð¥¤¥È¤Ç¤Ï¤Ê¤¯¥ï¥¤¥Éʸ»ú¤ËÂФ·¤ÆÁàºî¤ò¹Ô¤¦ÅÀ¤¬°Û¤Ê¤ë¡£
303 .\"O .SH "RETURN VALUE"
304 .SH ÊÖ¤êÃÍ
305 .\"O Upon successful completion
306 .\"O .BR fmemopen (),
307 .\"O .BR open_memstream ()
308 .\"O and
309 .\"O .BR open_wmemstream ()
310 .\"O return a
311 .\"O .I FILE
312 .\"O pointer.
313 .\"O Otherwise, NULL is returned and
314 .\"O .I errno
315 .\"O is set to indicate the error.
316 À®¸ù¤·¤Æ½ªÎ»¤·¤¿¾ì¹ç¤Ë¤Ï¡¢
317 .BR fmemopen (),
318 .BR open_memstream (),
319 .BR open_wmemstream ()
320 ¤Ï
321 .I FILE
322 ¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£
323 ¼ºÇÔ¤·¤¿¾ì¹ç¤Ï¡¢ NULL ¤òÊÖ¤·¡¢
324 .I errno
325 ¤Ë¥¨¥é¡¼¤ò¼¨¤¹Ãͤò¥»¥Ã¥È¤¹¤ë¡£
326 .\"O .SH VERSIONS
327 .SH ¥Ð¡¼¥¸¥ç¥ó
328 .\"O .BR fmemopen ()
329 .\"O and
330 .\"O .BR open_memstream ()
331 .\"O were already available in glibc 1.0.x.
332 .\"O .BR open_wmemstream ()
333 .\"O is available since glibc 2.4.
334 .BR fmemopen ()
335 ¤È
336 .BR open_memstream ()
337 ¤Ï glibc 1.0.x ¤Ç¤¹¤Ç¤ËÍøÍѲÄǽ¤Ç¤¢¤Ã¤¿¡£
338 .BR open_wmemstream ()
339 ¤Ï glibc 2.4 °Ê¹ß¤ÇÍøÍѲÄǽ¤Ç¤¢¤ë¡£
340 .\"O .SH "CONFORMING TO"
341 .SH ½àµò
342 POSIX.1-2008.
343 .\"O These functions are not specified in POSIX.1-2001,
344 .\"O and are not widely available on other systems.
345 ¤³¤ì¤é¤Î´Ø¿ô¤Ï POSIX.1-2001 ¤Ç¤Ïµ¬Äê¤ì¤Æ¤¤¤Ê¤¤¤¬¡¢
346 Linux °Ê³°¤Î¥·¥¹¥Æ¥à¤Ç¹­¤¯ÍøÍѲÄǽ¤Ç¤¢¤ë¡£
347 .\"O .SH NOTES
348 .SH Ãí°Õ
349 .\"O There is no file descriptor associated with the file stream
350 .\"O returned by these functions
351 .\"O (i.e.,
352 .\"O .BR fileno (3)
353 .\"O will return an error if called on the returned stream).
354 ¤³¤ì¤é¤Î´Ø¿ô¤¬ÊÖ¤¹¥Õ¥¡¥¤¥ë¥¹¥È¥ê¡¼¥à¤ËÂбþ¤¹¤ë¥Õ¥¡¥¤¥ë
355 ¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Ï¤Ê¤¤ (¤Ä¤Þ¤ê¡¢ÊÖ¤µ¤ì¤¿¥¹¥È¥ê¡¼¥à¤ËÂФ·¤Æ
356 .BR fileno (3)
357 ¤ò¸Æ¤Ó½Ð¤¹¤È¥¨¥é¡¼¤¬Ê֤뤳¤È¤Ë¤Ê¤ë)¡£
358 .\"O .SH BUGS
359 .SH ¥Ð¥°
360 .\"O In glibc before version 2.7, seeking past the end of a stream created by
361 .\"O .BR open_memstream ()
362 .\"O does not enlarge the buffer; instead the
363 .\"O .BR fseek (3)
364 .\"O call fails, returning \-1.
365 .\"O .\" http://sourceware.org/bugzilla/show_bug.cgi?id=1996
366 ¥Ð¡¼¥¸¥ç¥ó 2.7 ¤è¤êÁ°¤Î glibc ¤Ç¤Ï¡¢
367 .BR open_memstream ()
368 ¤ÇºîÀ®¤µ¤ì¤¿¥¹¥È¥ê¡¼¥à¤ÎËöÈø¤è¤êÀè¤Ë¥Õ¥¡¥¤¥ë°ÌÃÖ¤òÆ°¤«¤·¤Æ¤â¡¢
369 ¥Ð¥Ã¥Õ¥¡¤¬¿­Ä¹¤µ¤ì¤º¡¢
370 .BR fseek (3)
371 ¤¬¼ºÇÔ¤· \-1 ¤¬Ê֤롣
372 .\" http://sourceware.org/bugzilla/show_bug.cgi?id=1996
373 .\"O .SH "EXAMPLE"
374 .SH Îã
375 .\"O The program below uses
376 .\"O .BR fmemopen ()
377 .\"O to open an input buffer, and
378 .\"O .BR open_memstream ()
379 .\"O to open a dynamically sized output buffer.
380 .\"O The program scans its input string (taken from the program's
381 .\"O first command-line argument) reading integers,
382 .\"O and writes the squares of these integers to the output buffer.
383 .\"O An example of the output produced by this program is the following:
384 ¤³¤Î¥×¥í¥°¥é¥à¤Ï
385 .BR fmemopen ()
386 ¤ò»È¤Ã¤Æ½ÐÎϥХåե¡¤ò¥ª¡¼¥×¥ó¤·¡¢
387 .BR open_memstream ()
388 ¤ò»È¤Ã¤ÆưŪ¤Ë¥µ¥¤¥º¤¬ÊѲ½¤¹¤ë½ÐÎϥХåե¡¤ò¥ª¡¼¥×¥ó¤·¤Æ¤¤¤ë¡£
389 (¥×¥í¥°¥é¥à¤ÎÂè°ì¥³¥Þ¥ó¥É¥é¥¤¥ó°ú¤­¿ô¤«¤é¼è¤Ã¤¿) ÆþÎÏʸ»úÎó¤ò
390 ¥¹¥­¥ã¥ó¤·¤ÆÀ°¿ô¤òÆɤ߹þ¤ß¡¢¤³¤ì¤é¤ÎÀ°¿ô¤ÎÆó¾è¤ò½ÐÎϥХåե¡¤Ë½ñ¤­½Ð¤¹¡£
391 ¤³¤Î¥×¥í¥°¥é¥à¤Î¼Â¹ÔÎã¤Ï°Ê²¼¤Î¤è¤¦¤Ë¤Ê¤ë¡£
392 .in +4n
393 .nf
394
395 .RB "$" " ./a.out \(aq1 23 43\(aq"
396 size=11; ptr=1 529 1849
397 .fi
398 .in
399 .\"O .SS Program source
400 .SS ¥×¥í¥°¥é¥à¤Î¥½¡¼¥¹
401 \&
402 .nf
403 #define _GNU_SOURCE
404 #include <string.h>
405 #include <stdio.h>
406 #include <stdlib.h>
407
408 #define handle_error(msg) \\
409     do { perror(msg); exit(EXIT_FAILURE); } while (0)
410
411 int
412 main(int argc, char *argv[])
413 {
414     FILE *out, *in;
415     int v, s;
416     size_t size;
417     char *ptr;
418
419     if (argc != 2) {
420         fprintf(stderr, "Usage: %s <file>\\n", argv[0]);
421         exit(EXIT_FAILURE);
422     }
423
424     in = fmemopen(argv[1], strlen(argv[1]), "r");
425     if (in == NULL)
426         handle_error("fmemopen");
427
428     out = open_memstream(&ptr, &size);
429     if (out == NULL)
430         handle_error("open_memstream");
431
432     for (;;) {
433         s = fscanf(in, "%d", &v);
434         if (s <= 0)
435             break;
436
437         s = fprintf(out, "%d ", v * v);
438         if (s == \-1)
439             handle_error("fprintf");
440     }
441     fclose(in);
442     fclose(out);
443     printf("size=%ld; ptr=%s\\n", (long) size, ptr);
444     free(ptr);
445     exit(EXIT_SUCCESS);
446 }
447 .fi
448 .\"O .SH "SEE ALSO"
449 .SH ´ØÏ¢¹àÌÜ
450 .BR fopen (3),
451 .BR fopencookie (3)