aboutsummaryrefslogtreecommitdiff
path: root/ja_JP.eucJP/man/man3/funopen.3
blob: 8d61d48ee70a0b6ee950fa9852d45ca9c073c6a2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
.\" Copyright (c) 1990, 1991, 1993
.\"	The Regents of the University of California.  All rights reserved.
.\"
.\" This code is derived from software contributed to Berkeley by
.\" Chris Torek.
.\" 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.
.\"
.\"     @(#)funopen.3	8.1 (Berkeley) 6/9/93
.\"
.\" $FreeBSD$
.Dd June 9, 1993
.Dt FUNOPEN 3
.Os
.Sh 名称
.Nm funopen ,
.Nm fropen ,
.Nm fwopen
.Nd ストリームのオープン
.Sh 書式
.Fd #include <stdio.h>
.Ft FILE *
.Fn funopen "const void *cookie" "int (*readfn)(void *, char *, int)" "int (*writefn)(void *, const char *, int)" "fpos_t (*seekfn)(void *, fpos_t, int)" "int (*closefn)(void *)"
.Ft FILE *
.Fn fropen "void  *cookie" "int  (*readfn)(void *, char *, int)"
.Ft FILE *
.Fn fwopen "void  *cookie" "int  (*writefn)(void *, const char *, int)"
.Sh 解説
.Fn funopen
関数は、最大
4 つの「
.Tn I/O
機能」にストリームを関連付けます。
.Fa readfn
か
.Fa writefn
を指定してください。適切に入力した
Null
ポインタとして、その他を指定することもできます。この
.Tn I/O
機能は、新しいストリームの読込み、書込み、シーク、クローズに使用されます。
.Pp
一般的に、機能を省略すると、作成されたストリームでの関連オペレーション 
の実行がエラーになります。クローズ機能を省略した場合、ストリームを閉じ
ると、バッファの出力がフラッシュされて問題なく終了します。  
.Pp
.Fa readfn ,
.Fa writefn ,
.Fa seekfn ,
.Fa closefn
の呼び出し規則は、それぞれ
.Xr read 2 ,
.Xr write 2 ,
.Xr seek 2 ,
.Xr close 2
のものと同じですが、従来のファイル記述子引数の場所で、
.Fn funopen
に指定された
.Fa cookie
引数が渡されるという違いがあります。
.Pp
読込み
.Tn I/O
機能と書込み
.Tn I/O
機能では、
.Xr setvbuf 3
を呼び出せば、完全にバッファ化されたストリームかラインでバッファ化され
たストリームで基礎となるバッファを変更できます。バッファに完全に情報を
入力したり、バッファを完全に空にしたりする必要はありません。しかし、バッ
ファ化されていないストリームからバッファ化されたストリームに変更したり、
ラインバッファリングフラグの状態を変更したりすることはできません。また、
最近指定されたもの以外で、バッファでの読込み呼び出しや書込み呼び出しの
準備をする必要があります。 
.Pp
すべてのユーザ
.Tn I/O
機能は、\-1 を戻すことでエラーを報告します。エラーが発生した場合、すべ
ての機能は外部変数  
.Va errno
を適切に設定する必要があります。
.Pp
.Fn closefn
でエラーが発生すると、ストリームは閉じます。
.Pp
便宜を図るため、インクルードファイル
.Aq Pa stdio.h
では、読込み機能か書込み機能だけを指定した
.Fn funopen
呼び出しのようなマクロ
.Fn fropen
と
.Fn fwopen
が定義されています。
.Sh 戻り値
問題なく終了すると、
.Fn funopen
は
.Dv FILE
ポインタを戻します。問題がある場合は
.Dv Null
が戻され、そのエラーを示す値にグローバル変数
.Va errno
が設定されます。
.Sh エラー
.Bl -tag -width [EINVAL]
.It Bq Er EINVAL
.Fn funopen
関数が、読込み機能か書込み機能なしで呼び出されました。
.Fn funopen
関数がエラーになると、ルーチン
.Xr malloc 3
に指定されたエラーに
.Va errno
が設定されることもあります。
.El
.Sh 関連項目
.Xr fcntl 2 ,
.Xr open 2 ,
.Xr fclose 3 ,
.Xr fopen 3 ,
.Xr fseek 3 ,
.Xr setbuf 3
.Sh 歴史
.Fn funopen
関数は、
.Bx 4.4 
に追加されました。
.Sh バグ
.Fn funopen
関数は、
.Bx
以外のシステムに移植できないことがあります。