OSDN Git Service

a384bb9c59511aef64387d1d1bd3e6f52a7902fc
[linuxjm/LDP_man-pages.git] / draft / man2 / tee.2
1 .\" Hey Emacs! This file is -*- nroff -*- source.
2 .\"
3 .\" This manpage is Copyright (C) 2006 Jens Axboe
4 .\" and Copyright (C) 2006 Michael Kerrisk <mtk.manpages@gmail.com>
5 .\"
6 .\" Permission is granted to make and distribute verbatim copies of this
7 .\" manual provided the copyright notice and this permission notice are
8 .\" preserved on all copies.
9 .\"
10 .\" Permission is granted to copy and distribute modified versions of this
11 .\" manual under the conditions for verbatim copying, provided that the
12 .\" entire resulting derived work is distributed under the terms of a
13 .\" permission notice identical to this one.
14 .\"
15 .\" Since the Linux kernel and libraries are constantly changing, this
16 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
17 .\" responsibility for errors or omissions, or for damages resulting from
18 .\" the use of the information contained herein.  The author(s) may not
19 .\" have taken the same level of care in the production of this manual,
20 .\" which is licensed free of charge, as they might when working
21 .\" professionally.
22 .\"
23 .\" Formatted or processed versions of this manual, if unaccompanied by
24 .\" the source, must acknowledge the copyright and authors of this work.
25 .\"
26 .\" Japanese Version Copyright (c) 2007  Akihiro MOTOKI
27 .\"         all rights reserved.
28 .\" Translated 2007-02-04, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
29 .\" 
30 .TH TEE 2 2009-09-15 "Linux" "Linux Programmer's Manual"
31 .\"O .SH NAME
32 .SH 名前
33 .\"O tee \- duplicating pipe content
34 tee \- パイプの中身を複製する
35 .\"O .SH SYNOPSIS
36 .SH 書式
37 .nf
38 .\"O .BR "#define _GNU_SOURCE" "         /* See feature_test_macros(7) */"
39 .BR "#define _GNU_SOURCE" "         /* feature_test_macros(7) 参照 */"
40 .B #include <fcntl.h>
41
42 .BI "ssize_t tee(int " fd_in ", int " fd_out ", size_t " len \
43 ", unsigned int " flags );
44 .fi
45 .\" Return type was long before glibc 2.7
46 .\"O .SH DESCRIPTION
47 .SH 説明
48 .\" Example programs http://brick.kernel.dk/snaps
49 .\"
50 .\"
51 .\" add a "tee(in, out1, out2)" system call that duplicates the pages
52 .\" (again, incrementing their reference count, not copying the data) from
53 .\" one pipe to two other pipes.
54 .\"O .BR tee ()
55 .\"O duplicates up to
56 .\"O .I len
57 .\"O bytes of data from the pipe referred to by the file descriptor
58 .\"O .I fd_in
59 .\"O to the pipe referred to by the file descriptor
60 .\"O .IR fd_out .
61 .\"O It does not consume the data that is duplicated from
62 .\"O .IR fd_in ;
63 .\"O therefore, that data can be copied by a subsequent
64 .\"O .BR splice (2).
65 .BR tee ()
66 は、ファイルディスクリプタ
67 .I fd_in
68 が参照するパイプからファイルディスクリプタ
69 .I fd_out
70 が参照するパイプへ最大
71 .I len
72 バイトのデータを複製する。
73 この操作では、複製されるデータは
74 .I fd_in
75 からは消費されない。したがって、これらのデータをこの後の
76 .BR splice (2)
77 でコピーすることができる。
78
79 .\"O .I flags
80 .\"O is a series of modifier flags, which share the name space with
81 .\"O .BR splice (2)
82 .\"O and
83 .\"O .BR vmsplice (2):
84 .I flags
85 は一連の修飾フラグであり、
86 .BR splice (2)
87
88 .BR vmsplice (2)
89 と共通の名前である。
90 .TP 1.9i
91 .B SPLICE_F_MOVE
92 .\"O Currently has no effect for
93 .\"O .BR tee ();
94 .\"O see
95 .\"O .BR splice (2).
96 現在のところ
97 .BR tee ()
98 では何の効果もない。
99 .BR splice (2)
100 参照。
101 .TP
102 .B SPLICE_F_NONBLOCK
103 .\"O Do not block on I/O; see
104 .\"O .BR splice (2)
105 .\"O for further details.
106 入出力時に停止 (block) しない。
107 詳細は
108 .BR splice (2)
109 参照。
110 .TP
111 .B SPLICE_F_MORE
112 .\"O Currently has no effect for
113 .\"O .BR tee (),
114 .\"O but may be implemented in the future; see
115 .\"O .BR splice (2).
116 現在のところ
117 .BR tee ()
118 では何の効果もないが、将来的には実装される可能性がある。
119 .BR splice (2)
120 参照。
121 .TP
122 .B SPLICE_F_GIFT
123 .\"O Unused for
124 .\"O .BR tee ();
125 .\"O see
126 .\"O .BR vmsplice (2).
127 .BR tee ()
128 では未使用。
129 .BR vmsplice (2)
130 参照。
131 .\"O .SH RETURN VALUE
132 .SH 返り値
133 .\"O Upon successful completion,
134 .\"O .BR tee ()
135 .\"O returns the number of bytes that were duplicated between the input
136 .\"O and output.
137 .\"O A return value of 0 means that there was no data to transfer,
138 .\"O and it would not make sense to block, because there are no
139 .\"O writers connected to the write end of the pipe referred to by
140 .\"O .IR fd_in .
141 成功して完了すると、
142 .BR tee ()
143 は入出力間で複製されたバイト数を返す。
144 返り値 0 はデータの転送が行われなかったことを示す。
145 この場合、処理を停止 (block) しても無意味である。
146 なぜなら、
147 .I fd_in
148 が参照するパイプの書き込み側に接続されている者がいないからである。
149
150 .\"O On error,
151 .\"O .BR tee ()
152 .\"O returns \-1 and
153 .\"O .I errno
154 .\"O is set to indicate the error.
155 エラーの場合、
156 .BR tee ()
157 は \-1 を返し、
158 .I errno
159 にエラーを示す値を設定する。
160 .\"O .SH ERRORS
161 .SH エラー
162 .TP
163 .B EINVAL
164 .\"O .I fd_in
165 .\"O or
166 .\"O .I fd_out
167 .\"O does not refer to a pipe; or
168 .\"O .I fd_in
169 .\"O and
170 .\"O .I fd_out
171 .\"O refer to the same pipe.
172 .I fd_in
173
174 .I fd_out
175 のどちらかがパイプを参照していない。もしくは
176 .I fd_in
177
178 .I fd_out
179 が同じパイプを参照している。
180 .TP
181 .B ENOMEM
182 .\"O Out of memory.
183 メモリ不足。
184 .\"O .SH VERSIONS
185 .SH バージョン
186 .\"O The
187 .\"O .BR tee ()
188 .\"O system call first appeared in Linux 2.6.17.
189 .BR tee ()
190 システムコールは Linux 2.6.17 で初めて登場した。
191 .\"O .SH "CONFORMING TO"
192 .SH 準拠
193 .\"O This system call is Linux-specific.
194 このシステムコールは Linux 固有である。
195 .\"O .SH NOTES
196 .SH 注意
197 .\"O Conceptually,
198 .\"O .BR tee ()
199 .\"O copies the data between the two pipes.
200 .\"O In reality no real data copying takes place though:
201 .\"O under the covers,
202 .\"O .BR tee ()
203 .\"O assigns data in the output by merely grabbing
204 .\"O a reference to the input.
205 概念としては、
206 .BR tee ()
207 は二つのパイプ間でデータのコピーを行う。
208 しかし、実際には実データのコピーは行われない。
209 内部では、
210 .BR tee ()
211 は入力側に対する参照だけを作成することで出力側にデータを
212 追加する。
213 .\"O .SH EXAMPLE
214 .SH 例
215 .\"O The following example implements a basic
216 .\"O .BR tee (1)
217 .\"O program using the
218 .\"O .BR tee ()
219 .\"O system call.
220 以下の例は、
221 .BR tee ()
222 システムコールを使って、
223 基本的な
224 .BR tee (1)
225 プログラムを実装したものである。
226 .nf
227
228 #define _GNU_SOURCE
229 #include <fcntl.h>
230 #include <stdio.h>
231 #include <stdlib.h>
232 #include <unistd.h>
233 #include <errno.h>
234 #include <limits.h>
235
236 int
237 main(int argc, char *argv[])
238 {
239     int fd;
240     int len, slen;
241
242     if (argc != 2) {
243         fprintf(stderr, "Usage: %s <file>\\n", argv[0]);
244         exit(EXIT_FAILURE);
245     }
246
247     fd = open(argv[1], O_WRONLY | O_CREAT | O_TRUNC, 0644);
248     if (fd == \-1) {
249         perror("open");
250         exit(EXIT_FAILURE);
251     }
252
253     do {
254         /*
255          * tee stdin to stdout.
256          */
257         len = tee(STDIN_FILENO, STDOUT_FILENO,
258                   INT_MAX, SPLICE_F_NONBLOCK);
259
260         if (len < 0) {
261             if (errno == EAGAIN)
262                 continue;
263             perror("tee");
264             exit(EXIT_FAILURE);
265         } else
266             if (len == 0)
267                 break;
268
269         /*
270          * Consume stdin by splicing it to a file.
271          */
272         while (len > 0) {
273             slen = splice(STDIN_FILENO, NULL, fd, NULL,
274                           len, SPLICE_F_MOVE);
275             if (slen < 0) {
276                 perror("splice");
277                 break;
278             }
279             len \-= slen;
280         }
281     } while (1);
282
283     close(fd);
284     exit(EXIT_SUCCESS);
285 }
286 .fi
287 .\"O .SH SEE ALSO
288 .SH 関連項目
289 .BR splice (2),
290 .BR vmsplice (2)