OSDN Git Service

df746a839547b2c21fd917a86c5ac52220c30431
[linuxjm/LDP_man-pages.git] / draft / man3 / setbuf.3
1 .\" Copyright (c) 1980, 1991 Regents of the University of California.
2 .\" All rights reserved.
3 .\"
4 .\" This code is derived from software contributed to Berkeley by
5 .\" the American National Standards Committee X3, on Information
6 .\" Processing Systems.
7 .\"
8 .\" %%%LICENSE_START(BSD_4_CLAUSE_UCB)
9 .\" Redistribution and use in source and binary forms, with or without
10 .\" modification, are permitted provided that the following conditions
11 .\" are met:
12 .\" 1. Redistributions of source code must retain the above copyright
13 .\"    notice, this list of conditions and the following disclaimer.
14 .\" 2. Redistributions in binary form must reproduce the above copyright
15 .\"    notice, this list of conditions and the following disclaimer in the
16 .\"    documentation and/or other materials provided with the distribution.
17 .\" 3. All advertising materials mentioning features or use of this software
18 .\"    must display the following acknowledgement:
19 .\"     This product includes software developed by the University of
20 .\"     California, Berkeley and its contributors.
21 .\" 4. Neither the name of the University nor the names of its contributors
22 .\"    may be used to endorse or promote products derived from this software
23 .\"    without specific prior written permission.
24 .\"
25 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 .\" SUCH DAMAGE.
36 .\" %%%LICENSE_END
37 .\"
38 .\"     @(#)setbuf.3    6.10 (Berkeley) 6/29/91
39 .\"
40 .\" Converted for Linux, Mon Nov 29 14:55:24 1993, faith@cs.unc.edu
41 .\" Added section to BUGS, Sun Mar 12 22:28:33 MET 1995,
42 .\"                   Thomas.Koenig@ciw.uni-karlsruhe.de
43 .\" Correction,  Sun, 11 Apr 1999 15:55:18,
44 .\"     Martin Vicente <martin@netadmin.dgac.fr>
45 .\" Correction,  2000-03-03, Andreas Jaeger <aj@suse.de>
46 .\" Added return value for setvbuf, aeb,
47 .\"
48 .\"*******************************************************************
49 .\"
50 .\" This file was generated with po4a. Translate the source file.
51 .\"
52 .\"*******************************************************************
53 .TH SETBUF 3 2012\-08\-03 Linux "Linux Programmer's Manual"
54 .SH 名前
55 setbuf, setbuffer, setlinebuf, setvbuf \- ストリームのバッファリングの操作
56 .SH 書式
57 .nf
58 \fB#include <stdio.h>\fP
59
60 \fBvoid setbuf(FILE *\fP\fIstream\fP\fB, char *\fP\fIbuf\fP\fB);\fP
61
62 \fBvoid setbuffer(FILE *\fP\fIstream\fP\fB, char *\fP\fIbuf\fP\fB, size_t \fP\fIsize\fP\fB);\fP
63
64 \fBvoid setlinebuf(FILE *\fP\fIstream\fP\fB);\fP
65
66 \fBint setvbuf(FILE *\fP\fIstream\fP\fB, char *\fP\fIbuf\fP\fB, int \fP\fImode\fP\fB, size_t \fP\fIsize\fP\fB);\fP
67 .fi
68 .sp
69 .in -4n
70 glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7)  参照):
71 .in
72 .sp
73 \fBsetbuffer\fP(), \fBsetlinebuf\fP(): _BSD_SOURCE
74 .SH 説明
75 バッファリングには unbuffered, block buffered, line buffered の3つのタイプが ある。出力ストリームのタイプが
76 unbuffered の場合、データを書き込むとすぐに出 力先ファイルに書き込まれるかターミナルに表示される。block buffered の場合、文
77 字の読み書きはブロック単位でいっぺんに行われる。line buffered の場合、 新しい行が出力されるか、ターミナルデバイスに接続しているストリーム
78 (通常、\fIstdin\fP) から新しい行が入力されるまで文字がたくわえられる。 ブロックを強制的に出力するには \fBfflush\fP(3)  関数を使う。
79 (\fBfclose\fP(3)  を参照のこと) 通常、ファイルはすべて block buffered である。ファイルに対して 初めて入出力処理を行うと
80 \fBmalloc\fP(3)  が呼び出されバッファが獲得される。もし ストリームが (通常、 \fIstdout\fP がそうであるように)
81 ターミナルを参照する場合には、ファイルは line buffered と なる。標準エラー出力 \fIstderr\fP はデフォルトでは常に
82 unbuffered である。
83 .PP
84 \fBsetvbuf\fP()  関数は、オープンしている任意のストリームに対してバッファを変更できる。 引き数 \fImode\fP は、次の 3
85 つのマクロのうちいずれかである:
86 .RS
87 .TP 
88 \fB_IONBF\fP
89 unbuffered
90 .TP 
91 \fB_IOLBF\fP
92 line buffered
93 .TP 
94 \fB_IOFBF\fP
95 fully buffered
96 .RE
97 .PP
98 unbuffered のファイルを除き、 \fIbuf\fP 引数は \fIsize\fP
99 バイト以上の大きさのバッファを指していなければならない。このバッファは現在の バッファの代わりに用いられる。もし、引数 \fIbuf\fP が NULL
100 ならば、モードだけが変更される。 新しいバッファは次に読み書きした際に割り当てられる。 \fBsetvbuf\fP()  関数は、ストリームをオープンした後、
101 そのストリームに対して何らかの操作をする前にのみ使用できる。
102 .PP
103 他の 3 つの関数は \fBsetvbuf\fP()  の呼び出しに単純に置き換えることができる。 \fBsetbuf\fP()  関数は、
104 .PP
105 .in +4n
106 setvbuf(stream, buf, buf ? _IOFBF : _IONBF, BUFSIZ);
107 .in
108 .PP
109 と全く同等だし、 \fBsetbuffer\fP()  関数は、バッファサイズがデフォルト値 \fBBUFSIZ\fP ではなく引数で与えられる点以外は同じである。
110 \fBsetlinebuf\fP()  関数は以下と同じである。
111 .PP
112 .in +4n
113 setvbuf(stream, NULL, _IOLBF, 0);
114 .in
115 .SH 返り値
116 \fBsetvbuf\fP()  関数は、成功した場合 0 を返す。 失敗した場合、0 以外の値を返す (失敗とは、 \fImode\fP
117 が不正な場合またはリクエストが条件を満たさない場合である)。 \fBsetvbuf\fP()  関数が失敗した場合は \fIerrno\fP を設定することもある。
118
119 その他の関数は値を返さない。
120 .SH 準拠
121 \fBsetbuf\fP()  関数および \fBsetvbuf\fP()  関数は C89 と C99 に準拠している。
122 .SH バグ
123 \fBsetbuffer\fP()  関数および \fBsetlinebuf\fP()  関数は 4.2BSD より前の BSD とは互換性がない。また Linux
124 でも(古いバージョン では)利用できないかもしれない。4.2BSD および 4.3BSD のシステムでは \fBsetbuf\fP()
125 は必ず追加のバッファーのサイズを使用するので、これも使うべきでない。
126 .P
127 \fIstream\fP を閉じる時 (プログラムを終了する際にもこれは起きる) には、 \fIbuf\fP
128 が指し示す空間とが存在していることを保証しなければならない。 例えば、次のような使い方は許されない:
129 .nf
130 .sp
131 #include <stdio.h>
132
133 int
134 main(void)
135 {
136     char buf[BUFSIZ];
137     setbuf(stdin, buf);
138     printf("Hello, world!\en");
139     return 0;
140 }
141 .fi
142 .SH 関連項目
143 \fBfclose\fP(3), \fBfflush\fP(3), \fBfopen\fP(3), \fBfread\fP(3), \fBmalloc\fP(3),
144 \fBprintf\fP(3), \fBputs\fP(3)
145 .SH この文書について
146 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.52 の一部
147 である。プロジェクトの説明とバグ報告に関する情報は
148 http://www.kernel.org/doc/man\-pages/ に書かれている。