OSDN Git Service

Update release for LDP 3.67
[linuxjm/LDP_man-pages.git] / release / 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 .\"
54 .\" Japanese Version Copyright (c) 1999 ishikawa, keisuke
55 .\"         all rights reserved.
56 .\" Translated Thu Jan  7 00:03:12 JST 1999
57 .\"         by ishikawa, keisuke <ishikawa@sgk.gr.jp>
58 .\" Updated Sat May 19 JST 2001 by Kentaro Shirakata <argrath@ub32.org>
59 .\" Updated & Modified Sun Jul  1 15:48:32 JST 2001
60 .\"         by Yuichi SATO <ysato@h4.dion.ne.jp>
61 .\"
62 .TH SETBUF 3 2014\-02\-18 Linux "Linux Programmer's Manual"
63 .SH 名前
64 setbuf, setbuffer, setlinebuf, setvbuf \- ストリームのバッファリングの操作
65 .SH 書式
66 .nf
67 \fB#include <stdio.h>\fP
68
69 \fBvoid setbuf(FILE *\fP\fIstream\fP\fB, char *\fP\fIbuf\fP\fB);\fP
70
71 \fBvoid setbuffer(FILE *\fP\fIstream\fP\fB, char *\fP\fIbuf\fP\fB, size_t \fP\fIsize\fP\fB);\fP
72
73 \fBvoid setlinebuf(FILE *\fP\fIstream\fP\fB);\fP
74
75 \fBint setvbuf(FILE *\fP\fIstream\fP\fB, char *\fP\fIbuf\fP\fB, int \fP\fImode\fP\fB, size_t \fP\fIsize\fP\fB);\fP
76 .fi
77 .sp
78 .in -4n
79 glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7)  参照):
80 .in
81 .sp
82 \fBsetbuffer\fP(), \fBsetlinebuf\fP(): _BSD_SOURCE
83 .SH 説明
84 バッファリングには unbuffered, block buffered, line buffered の3つのタイプが ある。出力ストリームのタイプが
85 unbuffered の場合、データを書き込むとすぐに出 力先ファイルに書き込まれるかターミナルに表示される。block buffered の場合、文
86 字の読み書きはブロック単位でいっぺんに行われる。line buffered の場合、 新しい行が出力されるか、ターミナルデバイスに接続しているストリーム
87 (通常、\fIstdin\fP) から新しい行が入力されるまで文字がたくわえられる。 ブロックを強制的に出力するには \fBfflush\fP(3)  関数を使う。
88 (\fBfclose\fP(3)  を参照のこと) 通常、ファイルはすべて block buffered である。ファイルに対して 初めて入出力処理を行うと
89 \fBmalloc\fP(3)  が呼び出されバッファが獲得される。もし ストリームが (通常、 \fIstdout\fP がそうであるように)
90 ターミナルを参照する場合には、ファイルは line buffered と なる。標準エラー出力 \fIstderr\fP はデフォルトでは常に
91 unbuffered である。
92 .PP
93 \fBsetvbuf\fP()  関数は、オープンしている任意のストリームに対してバッファを変更できる。 引き数 \fImode\fP は、次の 3
94 つのマクロのうちいずれかである:
95 .RS
96 .TP 
97 \fB_IONBF\fP
98 unbuffered
99 .TP 
100 \fB_IOLBF\fP
101 line buffered
102 .TP 
103 \fB_IOFBF\fP
104 fully buffered
105 .RE
106 .PP
107 unbuffered のファイルを除き、 \fIbuf\fP 引数は \fIsize\fP
108 バイト以上の大きさのバッファを指していなければならない。このバッファは現在の バッファの代わりに用いられる。もし、引数 \fIbuf\fP が NULL
109 ならば、モードだけが変更される。 新しいバッファは次に読み書きした際に割り当てられる。 \fBsetvbuf\fP()  関数は、ストリームをオープンした後、
110 そのストリームに対して何らかの操作をする前にのみ使用できる。
111 .PP
112 他の 3 つの関数は \fBsetvbuf\fP()  の呼び出しに単純に置き換えることができる。 \fBsetbuf\fP()  関数は、
113 .PP
114 .in +4n
115 setvbuf(stream, buf, buf ? _IOFBF : _IONBF, BUFSIZ);
116 .in
117 .PP
118 と全く同等だし、 \fBsetbuffer\fP()  関数は、バッファサイズがデフォルト値 \fBBUFSIZ\fP ではなく引数で与えられる点以外は同じである。
119 \fBsetlinebuf\fP()  関数は以下と同じである。
120 .PP
121 .in +4n
122 setvbuf(stream, NULL, _IOLBF, 0);
123 .in
124 .SH 返り値
125 \fBsetvbuf\fP()  関数は、成功した場合 0 を返す。 失敗した場合、0 以外の値を返す (失敗とは、 \fImode\fP
126 が不正な場合またはリクエストが条件を満たさない場合である)。 \fBsetvbuf\fP()  関数が失敗した場合は \fIerrno\fP を設定することもある。
127
128 その他の関数は値を返さない。
129 .SH 属性
130 .SS "マルチスレッディング (pthreads(7) 参照)"
131 関数 \fBsetbuf\fP(), \fBsetbuffer\fP(), \fBsetlinebuf\fP(), \fBsetvbuf\fP() はスレッドセーフである。
132 .SH 準拠
133 \fBsetbuf\fP()  関数および \fBsetvbuf\fP()  関数は C89 と C99 に準拠している。
134 .SH バグ
135 \fBsetbuffer\fP()  関数および \fBsetlinebuf\fP()  関数は 4.2BSD より前の BSD とは互換性がない。また Linux
136 でも(古いバージョン では)利用できないかもしれない。4.2BSD および 4.3BSD のシステムでは \fBsetbuf\fP()
137 は必ず追加のバッファーのサイズを使用するので、これも使うべきでない。
138 .P
139 \fIstream\fP を閉じる時 (プログラムを終了する際にもこれは起きる) には、 \fIbuf\fP
140 が指し示す空間とが存在していることを保証しなければならない。 例えば、次のような使い方は許されない:
141 .nf
142 .sp
143 #include <stdio.h>
144
145 int
146 main(void)
147 {
148     char buf[BUFSIZ];
149     setbuf(stdin, buf);
150     printf("Hello, world!\en");
151     return 0;
152 }
153 .fi
154 .SH 関連項目
155 \fBfclose\fP(3), \fBfflush\fP(3), \fBfopen\fP(3), \fBfread\fP(3), \fBmalloc\fP(3),
156 \fBprintf\fP(3), \fBputs\fP(3)
157 .SH この文書について
158 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.67 の一部
159 である。プロジェクトの説明とバグ報告に関する情報は
160 http://www.kernel.org/doc/man\-pages/ に書かれている。