OSDN Git Service

ac3791a6ecff99e775832db240ff0af5f4514479
[linuxjm/LDP_man-pages.git] / draft / man3 / setbuf.3
1 .\"
2 .\" Japanese Version Copyright (c) 1999 ishikawa, keisuke
3 .\"         all rights reserved.
4 .\" Translated Thu Jan  7 00:03:12 JST 1999
5 .\"         by ishikawa, keisuke <ishikawa@sgk.gr.jp>
6 .\" Updated Sat May 19 JST 2001 by Kentaro Shirakata <argrath@ub32.org>
7 .\" Updated & Modified Sun Jul  1 15:48:32 JST 2001
8 .\"         by Yuichi SATO <ysato@h4.dion.ne.jp>
9 .\"
10 .\" Copyright (c) 1980, 1991 Regents of the University of California.
11 .\" All rights reserved.
12 .\"
13 .\" This code is derived from software contributed to Berkeley by
14 .\" the American National Standards Committee X3, on Information
15 .\" Processing Systems.
16 .\"
17 .\" Redistribution and use in source and binary forms, with or without
18 .\" modification, are permitted provided that the following conditions
19 .\" are met:
20 .\" 1. Redistributions of source code must retain the above copyright
21 .\"    notice, this list of conditions and the following disclaimer.
22 .\" 2. Redistributions in binary form must reproduce the above copyright
23 .\"    notice, this list of conditions and the following disclaimer in the
24 .\"    documentation and/or other materials provided with the distribution.
25 .\" 3. All advertising materials mentioning features or use of this software
26 .\"    must display the following acknowledgement:
27 .\"     This product includes software developed by the University of
28 .\"     California, Berkeley and its contributors.
29 .\" 4. Neither the name of the University nor the names of its contributors
30 .\"    may be used to endorse or promote products derived from this software
31 .\"    without specific prior written permission.
32 .\"
33 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
34 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
35 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
36 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
37 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
38 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
39 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
40 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
41 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
42 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
43 .\" SUCH DAMAGE.
44 .\"
45 .\"     @(#)setbuf.3    6.10 (Berkeley) 6/29/91
46 .\"
47 .\" Converted for Linux, Mon Nov 29 14:55:24 1993, faith@cs.unc.edu
48 .\" Added section to BUGS, Sun Mar 12 22:28:33 MET 1995,
49 .\"                   Thomas.Koenig@ciw.uni-karlsruhe.de
50 .\" Correction,  Sun, 11 Apr 1999 15:55:18,
51 .\"     Martin Vicente <martin@netadmin.dgac.fr>
52 .\" Correction,  2000-03-03, Andreas Jaeger <aj@suse.de>
53 .\" Added return value for setvbuf, aeb,
54 .\"
55 .TH SETBUF 3  2008-06-26 "Linux" "Linux Programmer's Manual"
56 .\"O .SH NAME
57 .\"O setbuf, setbuffer, setlinebuf, setvbuf \- stream buffering operations
58 .SH 名前
59 setbuf, setbuffer, setlinebuf, setvbuf \- ストリームのバッファリングの操作
60 .\"O .SH SYNOPSIS
61 .SH 書式
62 .nf
63 .B #include <stdio.h>
64
65 .BI "void setbuf(FILE *" stream ", char *" buf );
66
67 .BI "void setbuffer(FILE *" stream ", char *" buf ", size_t "  size );
68
69 .BI "void setlinebuf(FILE *" stream );
70
71 .BI "int setvbuf(FILE *" stream ", char *" buf ", int " mode \
72 ", size_t " size );
73 .fi
74 .sp
75 .in -4n
76 .\"O Feature Test Macro Requirements for glibc (see
77 .\"O .BR feature_test_macros (7)):
78 glibc 向けの機能検査マクロの要件
79 .RB ( feature_test_macros (7)
80 参照):
81 .in
82 .sp
83 .BR setbuffer (),
84 .BR setlinebuf ():
85 _BSD_SOURCE
86 .\"O .SH DESCRIPTION
87 .\"O The three types of buffering available are unbuffered, block buffered, and
88 .\"O line buffered.
89 .\"O When an output stream is unbuffered, information appears on
90 .\"O the destination file or terminal as soon as written; when it is block
91 .\"O buffered many characters are saved up and written as a block; when it is
92 .\"O line buffered characters are saved up until a newline is output or input is
93 .\"O read from any stream attached to a terminal device (typically \fIstdin\fP).
94 .\"O The function
95 .\"O .BR fflush (3)
96 .\"O may be used to force the block out early.
97 .\"O (See
98 .\"O .BR fclose (3).)
99 .\"O Normally all files are block buffered.
100 .\"O When the first I/O operation occurs
101 .\"O on a file,
102 .\"O .BR malloc (3)
103 .\"O is called, and a buffer is obtained.
104 .\"O If a stream refers to a terminal (as
105 .\"O .I stdout
106 .\"O normally does) it is line buffered.
107 .\"O The standard error stream
108 .\"O .I stderr
109 .\"O is always unbuffered by default.
110 .SH 説明
111 バッファリングには unbuffered, block buffered, line buffered の3つのタイプが
112 ある。出力ストリームのタイプが unbuffered の場合、データを書き込むとすぐに出
113 力先ファイルに書き込まれるかターミナルに表示される。block buffered の場合、文
114 字の読み書きはブロック単位でいっぺんに行われる。line buffered の場合、
115 新しい行が出力されるか、ターミナルデバイスに接続しているストリーム
116 (通常、\fIstdin\fP) から新しい行が入力されるまで文字がたくわえられる。
117 ブロックを強制的に出力するには
118 .BR fflush (3)
119 関数を使う。
120 .RB ( fclose (3)
121 を参照のこと) 通常、ファイルはすべて block buffered である。ファイルに対して
122 初めて入出力処理を行うと
123 .BR malloc (3)
124 が呼び出されバッファが獲得される。もし ストリームが (通常、
125 .I stdout
126 がそうであるように) ターミナルを参照する場合には、ファイルは line buffered と
127 なる。標準エラー出力
128 .I stderr
129 はデフォルトでは常に unbuffered である。
130 .PP
131 .\"O The
132 .\"O .BR setvbuf ()
133 .\"O function may be used on any open stream to change its buffer.
134 .BR setvbuf ()
135 関数は、オープンしている任意のストリームに対してバッファを変更できる。
136 .\"O The
137 .\"O .I mode
138 .\"O argument must be one of the following three macros:
139 引き数
140 .I mode
141 は、次の 3 つのマクロのうちいずれかである:
142 .RS
143 .TP
144 .B _IONBF
145 unbuffered
146 .TP
147 .B _IOLBF
148 line buffered
149 .TP
150 .B _IOFBF
151 fully buffered
152 .RE
153 .PP
154 .\"O Except for unbuffered files, the
155 .\"O .I buf
156 .\"O argument should point to a buffer at least
157 .\"O .I size
158 .\"O bytes long; this buffer will be used instead of the current buffer.
159 .\"O If the argument
160 .\"O .I buf
161 .\"O is NULL,
162 .\"O only the mode is affected; a new buffer will be allocated on the next read
163 .\"O or write operation.
164 .\"O The
165 .\"O .BR setvbuf ()
166 .\"O function may only be used after opening a stream and before any other
167 .\"O operations have been performed on it.
168 unbuffered のファイルを除き、
169 .I buf
170 引数は
171 .I size
172 バイト以上の大きさのバッファを指していなければならない。このバッファは現在の
173 バッファの代わりに用いられる。もし、引数
174 .I buf
175 が NULL ならば、モードだけが変更される。
176 新しいバッファは次に読み書きした際に割り当てられる。
177 .BR setvbuf ()
178 関数は、ストリームをオープンした後、
179 そのストリームに対して何らかの操作をする前にのみ使用できる。
180 .PP
181 .\"O The other three calls are, in effect, simply aliases for calls to
182 .\"O .BR setvbuf ().
183 .\"O The
184 .\"O .BR setbuf ()
185 .\"O function is exactly equivalent to the call
186 .\"O .PP
187 .\"O .in +4n
188 .\"O setvbuf(stream, buf, buf ? _IOFBF : _IONBF, BUFSIZ);
189 .\"O .in
190 .\"O .PP
191 .\"O The
192 .\"O .BR setbuffer ()
193 .\"O function is the same, except that the size of the buffer is up to the
194 .\"O caller, rather than being determined by the default
195 .\"O .BR BUFSIZ .
196 .\"O The
197 .\"O .BR setlinebuf ()
198 .\"O function is exactly equivalent to the call:
199 .\"O .PP
200 .\"O .in +4n
201 .\"O setvbuf(stream, (char *) NULL, _IOLBF, 0);
202 .\"O .in
203 他の 3 つの関数は
204 .BR setvbuf ()
205 の呼び出しに単純に置き換えることができる。
206 .BR setbuf ()
207 関数は、
208 .PP
209 .in +4n
210 setvbuf(stream, buf, buf ? _IOFBF : _IONBF, BUFSIZ);
211
212 .in
213 と全く同等だし、
214 .BR setbuffer ()
215 関数は、バッファサイズがデフォルト値
216 .B BUFSIZ
217 ではなく引数で与えられる点以外は同じである。
218 .BR setlinebuf ()
219 関数は
220 .PP
221 .in +4n
222 setvbuf(stream, (char *) NULL, _IOLBF, 0);
223
224 .in
225 と同じである。
226 .\"O .SH "RETURN VALUE"
227 .SH 返り値
228 .\"O The function
229 .\"O .BR setvbuf ()
230 .\"O returns 0 on success.
231 .\"O It returns nonzero on failure
232 .\"O .RI ( mode
233 .\"O is invalid or the request cannot be honored).
234 .\"O It may set
235 .\"O .I errno
236 .\"O on failure.
237 .BR setvbuf ()
238 関数は、成功した場合 0 を返す。
239 失敗した場合、0 以外の値を返す
240 (失敗とは、
241 .I mode
242 が不正な場合またはリクエストが条件を満たさない場合である)。
243 .BR setvbuf ()
244 関数が失敗した場合は
245 .I errno
246 を設定することもある。
247
248 .\"O The other functions do not return a value.
249 その他の関数は値を返さない。
250 .\"O .SH "CONFORMING TO"
251 .SH 準拠
252 .\"O The
253 .\"O .BR setbuf ()
254 .\"O and
255 .\"O .BR setvbuf ()
256 .\"O functions conform to C89 and C99.
257 .BR setbuf ()
258 関数および
259 .BR setvbuf ()
260 関数は C89 と C99 に準拠している。
261 .\"O .SH BUGS
262 .SH バグ
263 .\"O The
264 .\"O .BR setbuffer ()
265 .\"O and
266 .\"O .BR setlinebuf ()
267 .\"O functions are not portable to versions of BSD before 4.2BSD, and may not be
268 .\"O available under Linux.
269 .\"O On 4.2BSD and 4.3BSD systems,
270 .\"O .BR setbuf ()
271 .\"O always uses a suboptimal buffer size and should be avoided.
272 .BR setbuffer ()
273 関数および
274 .BR setlinebuf ()
275 関数は 4.2BSD より前の BSD とは互換性がない。また Linux でも(古いバージョン
276 では)利用できないかもしれない。4.2BSD および 4.3BSD のシステムでは
277 .BR setbuf ()
278 は必ず追加のバッファーのサイズを使用するので、これも使うべきでない。
279 .P
280 .\"O You must make sure that the space that
281 .\"O .I buf
282 .\"O points to still exist by the time
283 .\"O .I stream
284 .\"O is closed, which also happens at program termination.
285 .\"O For example, the following is invalid:
286 .I stream
287 を閉じる時 (プログラムを終了する際にもこれは起きる) には、
288 .I buf
289 が指し示す空間とが存在していることを保証しなければならない。
290 例えば、次のような使い方は許されない:
291 .nf
292 .sp
293 #include <stdio.h>
294
295 int
296 main(void)
297 {
298     char buf[BUFSIZ];
299     setbuf(stdin, buf);
300     printf("Hello, world!\\n");
301     return 0;
302 }
303 .fi
304 .\"O .SH "SEE ALSO"
305 .SH 関連項目
306 .BR fclose (3),
307 .BR fflush (3),
308 .BR fopen (3),
309 .BR fread (3),
310 .BR malloc (3),
311 .BR printf (3),
312 .BR puts (3)