.\" .\" Japanese Version Copyright (c) 1999 ishikawa, keisuke .\" all rights reserved. .\" Translated Thu Jan 7 00:03:12 JST 1999 .\" by ishikawa, keisuke .\" Updated Sat May 19 JST 2001 by Kentaro Shirakata .\" Updated & Modified Sun Jul 1 15:48:32 JST 2001 .\" by Yuichi SATO .\" .\" Copyright (c) 1980, 1991 Regents of the University of California. .\" All rights reserved. .\" .\" This code is derived from software contributed to Berkeley by .\" the American National Standards Committee X3, on Information .\" Processing Systems. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. All advertising materials mentioning features or use of this software .\" must display the following acknowledgement: .\" This product includes software developed by the University of .\" California, Berkeley and its contributors. .\" 4. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" @(#)setbuf.3 6.10 (Berkeley) 6/29/91 .\" .\" Converted for Linux, Mon Nov 29 14:55:24 1993, faith@cs.unc.edu .\" Added section to BUGS, Sun Mar 12 22:28:33 MET 1995, .\" Thomas.Koenig@ciw.uni-karlsruhe.de .\" Correction, Sun, 11 Apr 1999 15:55:18, .\" Martin Vicente .\" Correction, 2000-03-03, Andreas Jaeger .\" Added return value for setvbuf, aeb, .\" .TH SETBUF 3 2008-06-26 "Linux" "Linux Programmer's Manual" .\"O .SH NAME .\"O setbuf, setbuffer, setlinebuf, setvbuf \- stream buffering operations .SH 名前 setbuf, setbuffer, setlinebuf, setvbuf \- ストリームのバッファリングの操作 .\"O .SH SYNOPSIS .SH 書式 .nf .B #include .BI "void setbuf(FILE *" stream ", char *" buf ); .BI "void setbuffer(FILE *" stream ", char *" buf ", size_t " size ); .BI "void setlinebuf(FILE *" stream ); .BI "int setvbuf(FILE *" stream ", char *" buf ", int " mode \ ", size_t " size ); .fi .sp .in -4n .\"O Feature Test Macro Requirements for glibc (see .\"O .BR feature_test_macros (7)): glibc 向けの機能検査マクロの要件 .RB ( feature_test_macros (7) 参照): .in .sp .BR setbuffer (), .BR setlinebuf (): _BSD_SOURCE .\"O .SH DESCRIPTION .\"O The three types of buffering available are unbuffered, block buffered, and .\"O line buffered. .\"O When an output stream is unbuffered, information appears on .\"O the destination file or terminal as soon as written; when it is block .\"O buffered many characters are saved up and written as a block; when it is .\"O line buffered characters are saved up until a newline is output or input is .\"O read from any stream attached to a terminal device (typically \fIstdin\fP). .\"O The function .\"O .BR fflush (3) .\"O may be used to force the block out early. .\"O (See .\"O .BR fclose (3).) .\"O Normally all files are block buffered. .\"O When the first I/O operation occurs .\"O on a file, .\"O .BR malloc (3) .\"O is called, and a buffer is obtained. .\"O If a stream refers to a terminal (as .\"O .I stdout .\"O normally does) it is line buffered. .\"O The standard error stream .\"O .I stderr .\"O is always unbuffered by default. .SH 説明 バッファリングには unbuffered, block buffered, line buffered の3つのタイプが ある。出力ストリームのタイプが unbuffered の場合、データを書き込むとすぐに出 力先ファイルに書き込まれるかターミナルに表示される。block buffered の場合、文 字の読み書きはブロック単位でいっぺんに行われる。line buffered の場合、 新しい行が出力されるか、ターミナルデバイスに接続しているストリーム (通常、\fIstdin\fP) から新しい行が入力されるまで文字がたくわえられる。 ブロックを強制的に出力するには .BR fflush (3) 関数を使う。 .RB ( fclose (3) を参照のこと) 通常、ファイルはすべて block buffered である。ファイルに対して 初めて入出力処理を行うと .BR malloc (3) が呼び出されバッファが獲得される。もし ストリームが (通常、 .I stdout がそうであるように) ターミナルを参照する場合には、ファイルは line buffered と なる。標準エラー出力 .I stderr はデフォルトでは常に unbuffered である。 .PP .\"O The .\"O .BR setvbuf () .\"O function may be used on any open stream to change its buffer. .BR setvbuf () 関数は、オープンしている任意のストリームに対してバッファを変更できる。 .\"O The .\"O .I mode .\"O argument must be one of the following three macros: 引き数 .I mode は、次の 3 つのマクロのうちいずれかである: .RS .TP .B _IONBF unbuffered .TP .B _IOLBF line buffered .TP .B _IOFBF fully buffered .RE .PP .\"O Except for unbuffered files, the .\"O .I buf .\"O argument should point to a buffer at least .\"O .I size .\"O bytes long; this buffer will be used instead of the current buffer. .\"O If the argument .\"O .I buf .\"O is NULL, .\"O only the mode is affected; a new buffer will be allocated on the next read .\"O or write operation. .\"O The .\"O .BR setvbuf () .\"O function may only be used after opening a stream and before any other .\"O operations have been performed on it. unbuffered のファイルを除き、 .I buf 引数は .I size バイト以上の大きさのバッファを指していなければならない。このバッファは現在の バッファの代わりに用いられる。もし、引数 .I buf が NULL ならば、モードだけが変更される。 新しいバッファは次に読み書きした際に割り当てられる。 .BR setvbuf () 関数は、ストリームをオープンした後、 そのストリームに対して何らかの操作をする前にのみ使用できる。 .PP .\"O The other three calls are, in effect, simply aliases for calls to .\"O .BR setvbuf (). .\"O The .\"O .BR setbuf () .\"O function is exactly equivalent to the call .\"O .PP .\"O .in +4n .\"O setvbuf(stream, buf, buf ? _IOFBF : _IONBF, BUFSIZ); .\"O .in .\"O .PP .\"O The .\"O .BR setbuffer () .\"O function is the same, except that the size of the buffer is up to the .\"O caller, rather than being determined by the default .\"O .BR BUFSIZ . .\"O The .\"O .BR setlinebuf () .\"O function is exactly equivalent to the call: .\"O .PP .\"O .in +4n .\"O setvbuf(stream, (char *) NULL, _IOLBF, 0); .\"O .in 他の 3 つの関数は .BR setvbuf () の呼び出しに単純に置き換えることができる。 .BR setbuf () 関数は、 .PP .in +4n setvbuf(stream, buf, buf ? _IOFBF : _IONBF, BUFSIZ); .in と全く同等だし、 .BR setbuffer () 関数は、バッファサイズがデフォルト値 .B BUFSIZ ではなく引数で与えられる点以外は同じである。 .BR setlinebuf () 関数は .PP .in +4n setvbuf(stream, (char *) NULL, _IOLBF, 0); .in と同じである。 .\"O .SH "RETURN VALUE" .SH 返り値 .\"O The function .\"O .BR setvbuf () .\"O returns 0 on success. .\"O It returns nonzero on failure .\"O .RI ( mode .\"O is invalid or the request cannot be honored). .\"O It may set .\"O .I errno .\"O on failure. .BR setvbuf () 関数は、成功した場合 0 を返す。 失敗した場合、0 以外の値を返す (失敗とは、 .I mode が不正な場合またはリクエストが条件を満たさない場合である)。 .BR setvbuf () 関数が失敗した場合は .I errno を設定することもある。 .\"O The other functions do not return a value. その他の関数は値を返さない。 .\"O .SH "CONFORMING TO" .SH 準拠 .\"O The .\"O .BR setbuf () .\"O and .\"O .BR setvbuf () .\"O functions conform to C89 and C99. .BR setbuf () 関数および .BR setvbuf () 関数は C89 と C99 に準拠している。 .\"O .SH BUGS .SH バグ .\"O The .\"O .BR setbuffer () .\"O and .\"O .BR setlinebuf () .\"O functions are not portable to versions of BSD before 4.2BSD, and may not be .\"O available under Linux. .\"O On 4.2BSD and 4.3BSD systems, .\"O .BR setbuf () .\"O always uses a suboptimal buffer size and should be avoided. .BR setbuffer () 関数および .BR setlinebuf () 関数は 4.2BSD より前の BSD とは互換性がない。また Linux でも(古いバージョン では)利用できないかもしれない。4.2BSD および 4.3BSD のシステムでは .BR setbuf () は必ず追加のバッファーのサイズを使用するので、これも使うべきでない。 .P .\"O You must make sure that the space that .\"O .I buf .\"O points to still exist by the time .\"O .I stream .\"O is closed, which also happens at program termination. .\"O For example, the following is invalid: .I stream を閉じる時 (プログラムを終了する際にもこれは起きる) には、 .I buf が指し示す空間とが存在していることを保証しなければならない。 例えば、次のような使い方は許されない: .nf .sp #include int main(void) { char buf[BUFSIZ]; setbuf(stdin, buf); printf("Hello, world!\\n"); return 0; } .fi .\"O .SH "SEE ALSO" .SH 関連項目 .BR fclose (3), .BR fflush (3), .BR fopen (3), .BR fread (3), .BR malloc (3), .BR printf (3), .BR puts (3)