OSDN Git Service

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