.\" 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. .\" .\" %%%LICENSE_START(BSD_4_CLAUSE_UCB) .\" 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. .\" %%%LICENSE_END .\" .\" @(#)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, .\" .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .\" .\" 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 .\" .TH SETBUF 3 2019\-03\-06 Linux "Linux Programmer's Manual" .SH 名前 setbuf, setbuffer, setlinebuf, setvbuf \- ストリームのバッファーリングの操作 .SH 書式 .nf \fB#include \fP .PP \fBvoid setbuf(FILE *\fP\fIstream\fP\fB, char *\fP\fIbuf\fP\fB);\fP .PP \fBvoid setbuffer(FILE *\fP\fIstream\fP\fB, char *\fP\fIbuf\fP\fB, size_t \fP\fIsize\fP\fB);\fP .PP \fBvoid setlinebuf(FILE *\fP\fIstream\fP\fB);\fP .PP \fBint setvbuf(FILE *\fP\fIstream\fP\fB, char *\fP\fIbuf\fP\fB, int \fP\fImode\fP\fB, size_t \fP\fIsize\fP\fB);\fP .fi .PP .RS -4 glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7) 参照): .RE .PP \fBsetbuffer\fP(), \fBsetlinebuf\fP(): Since glibc 2.19: _DEFAULT_SOURCE Glibc 2.19 and earlier: _BSD_SOURCE .SH 説明 バッファーリングには unbuffered, block buffered, line buffered の3つのタイプが ある。出力ストリームのタイプが unbuffered の場合、データを書き込むとすぐに出 力先ファイルに書き込まれるかターミナルに表示される。block buffered の場合、文 字の読み書きはブロック単位でいっぺんに行われる。line buffered の場合、 新しい行が出力されるか、ターミナルデバイスに接続しているストリーム (通常、\fIstdin\fP) から新しい行が入力されるまで文字がたくわえられる。 ブロックを強制的に出力するには \fBfflush\fP(3) 関数を使う。 (\fBfclose\fP(3) を参照のこと) .PP 通常、ファイルはすべて block buffered である。ストリームがターミナルを参照している場合 (\fIstdout\fP は通常ターミナルを参照している)、ストリームは line buffered となる。標準エラー出力 \fIstderr\fP はデフォルトでは常に unbuffered である。 .PP \fBsetvbuf\fP() 関数は、オープンしている任意のストリームに対してバッファーを変更できる。 引数 \fImode\fP は、次の 3 つのマクロのうちいずれかである: .RS .TP \fB_IONBF\fP unbuffered .TP \fB_IOLBF\fP line buffered .TP \fB_IOFBF\fP fully buffered .RE .PP unbuffered のファイルを除き、 \fIbuf\fP 引数は \fIsize\fP バイト以上の大きさのバッファーを指していなければならない。このバッファーは現在の バッファーの代わりに用いられる。もし、引数 \fIbuf\fP が NULL ならば、モードだけが変更される。 新しいバッファーは次に読み書きした際に割り当てられる。 \fBsetvbuf\fP() 関数は、ストリームをオープンした後、 そのストリームに対して何らかの操作をする前にのみ使用できる。 .PP 他の 3 つの関数は \fBsetvbuf\fP() の呼び出しに単純に置き換えることができる。 \fBsetbuf\fP() 関数は、 .PP .in +4n setvbuf(stream, buf, buf ? _IOFBF : _IONBF, BUFSIZ); .in .PP と全く同等だし、 \fBsetbuffer\fP() 関数は、バッファーサイズがデフォルト値 \fBBUFSIZ\fP ではなく引数で与えられる点以外は同じである。 \fBsetlinebuf\fP() 関数は以下と同じである。 .PP .in +4n setvbuf(stream, NULL, _IOLBF, 0); .in .SH 返り値 \fBsetvbuf\fP() 関数は、成功した場合 0 を返す。 失敗した場合、0 以外の値を返す (失敗とは、 \fImode\fP が不正な場合またはリクエストが条件を満たさない場合である)。 \fBsetvbuf\fP() 関数が失敗した場合は \fIerrno\fP を設定することもある。 .PP その他の関数は値を返さない。 .SH 属性 この節で使用されている用語の説明については、 \fBattributes\fP(7) を参照。 .TS allbox; lbw23 lb lb l l l. インターフェース 属性 値 T{ \fBsetbuf\fP(), \fBsetbuffer\fP(), .br \fBsetlinebuf\fP(), \fBsetvbuf\fP() T} Thread safety MT\-Safe .TE .SH 準拠 \fBsetbuf\fP() 関数および \fBsetvbuf\fP() 関数は C89 と C99 に準拠している。 .SH バグ .\" The .\" .BR setbuffer () .\" and .\" .BR setlinebuf () .\" functions are not portable to versions of BSD before 4.2BSD, and .\" are available under Linux since libc 4.5.21. .\" On 4.2BSD and 4.3BSD systems, .\" .BR setbuf () .\" always uses a suboptimal buffer size and should be avoided. .\".PP \fIstream\fP を閉じる時 (プログラムを終了する際にもこれは起きる) には、 \fIbuf\fP が指し示す空間とが存在していることを保証しなければならない。 例えば、次のような使い方は許されない: .PP .EX #include int main(void) { char buf[BUFSIZ]; setbuf(stdin, buf); printf("Hello, world!\en"); return 0; } .EE .SH 関連項目 \fBstdbuf\fP(1), \fBfclose\fP(3), \fBfflush\fP(3), \fBfopen\fP(3), \fBfread\fP(3), \fBmalloc\fP(3), \fBprintf\fP(3), \fBputs\fP(3) .SH この文書について この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 5.10 の一部である。プロジェクトの説明とバグ報告に関する情報は \%https://www.kernel.org/doc/man\-pages/ に書かれている。