OSDN Git Service

Update README
[linuxjm/LDP_man-pages.git] / release / man2 / tee.2
1 .\" This manpage is Copyright (C) 2006 Jens Axboe
2 .\" and Copyright (C) 2006 Michael Kerrisk <mtk.manpages@gmail.com>
3 .\"
4 .\" %%%LICENSE_START(VERBATIM)
5 .\" Permission is granted to make and distribute verbatim copies of this
6 .\" manual provided the copyright notice and this permission notice are
7 .\" preserved on all copies.
8 .\"
9 .\" Permission is granted to copy and distribute modified versions of this
10 .\" manual under the conditions for verbatim copying, provided that the
11 .\" entire resulting derived work is distributed under the terms of a
12 .\" permission notice identical to this one.
13 .\"
14 .\" Since the Linux kernel and libraries are constantly changing, this
15 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
16 .\" responsibility for errors or omissions, or for damages resulting from
17 .\" the use of the information contained herein.  The author(s) may not
18 .\" have taken the same level of care in the production of this manual,
19 .\" which is licensed free of charge, as they might when working
20 .\" professionally.
21 .\"
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
24 .\" %%%LICENSE_END
25 .\"
26 .\"*******************************************************************
27 .\"
28 .\" This file was generated with po4a. Translate the source file.
29 .\"
30 .\"*******************************************************************
31 .\"
32 .\" Japanese Version Copyright (c) 2007  Akihiro MOTOKI
33 .\"         all rights reserved.
34 .\" Translated 2007-02-04, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
35 .\"
36 .TH TEE 2 2014\-12\-31 Linux "Linux Programmer's Manual"
37 .SH 名前
38 tee \- パイプの中身を複製する
39 .SH 書式
40 .nf
41 \fB#define _GNU_SOURCE\fP         /* feature_test_macros(7) 参照 */
42 \fB#include <fcntl.h>\fP
43
44 \fBssize_t tee(int \fP\fIfd_in\fP\fB, int \fP\fIfd_out\fP\fB, size_t \fP\fIlen\fP\fB, unsigned int \fP\fIflags\fP\fB);\fP
45 .fi
46 .\" Return type was long before glibc 2.7
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 \fBtee\fP()  は、ファイルディスクリプター \fIfd_in\fP が参照するパイプからファイルディスクリプター \fIfd_out\fP
55 が参照するパイプへ最大 \fIlen\fP バイトのデータを複製する。 この操作では、複製されるデータは \fIfd_in\fP
56 からは消費されない。したがって、これらのデータをこの後の \fBsplice\fP(2)  でコピーすることができる。
57
58 \fIflags\fP は一連の修飾フラグであり、 \fBsplice\fP(2)  や \fBvmsplice\fP(2)  と共通の名前である。
59 .TP  1.9i
60 \fBSPLICE_F_MOVE\fP
61 現在のところ \fBtee\fP()  では何の効果もない。 \fBsplice\fP(2)  参照。
62 .TP 
63 \fBSPLICE_F_NONBLOCK\fP
64 入出力で停止 (block) しない。詳細は \fBsplice\fP(2)  参照。
65 .TP 
66 \fBSPLICE_F_MORE\fP
67 現在のところ \fBtee\fP()  では何の効果もないが、将来的には実装される可能性がある。 \fBsplice\fP(2)  参照。
68 .TP 
69 \fBSPLICE_F_GIFT\fP
70 \fBtee\fP()  では未使用。 \fBvmsplice\fP(2)  参照。
71 .SH 返り値
72 成功して完了すると、 \fBtee\fP()  は入出力間で複製されたバイト数を返す。 返り値 0 はデータの転送が行われなかったことを示す。
73 この場合、処理を停止 (block) しても無意味である。 なぜなら、 \fIfd_in\fP
74 が参照するパイプの書き込み側に接続されている者がいないからである。
75
76 エラーの場合、 \fBtee\fP()  は \-1 を返し、 \fIerrno\fP にエラーを示す値を設定する。
77 .SH エラー
78 .TP 
79 \fBEAGAIN\fP
80 \fBSPLICE_F_NONBLOCK\fP が \fIflags\fP に指定されていて、かつ操作が停止するような状態であった。
81 .TP 
82 \fBEINVAL\fP
83 \fIfd_in\fP と \fIfd_out\fP のどちらかがパイプを参照していない。もしくは \fIfd_in\fP と \fIfd_out\fP
84 が同じパイプを参照している。
85 .TP 
86 \fBENOMEM\fP
87 メモリー不足。
88 .SH バージョン
89 \fBtee\fP() システムコールは Linux 2.6.17 で初めて登場した。
90 ライブラリによるサポートは glibc バージョン 2.5 で追加された。
91 .SH 準拠
92 このシステムコールは Linux 固有である。
93 .SH 注意
94 概念としては、 \fBtee\fP()  は二つのパイプ間でデータのコピーを行う。 しかし、実際には実データのコピーは行われない。 内部では、
95 \fBtee\fP()  は入力側に対する参照だけを作成することで出力側にデータを 追加する。
96 .SH 例
97 以下の例は、 \fBtee\fP()  システムコールを使って、 基本的な \fBtee\fP(1)  プログラムを実装したものである。 以下は利用例である。
98
99 .in +4n
100 .nf
101 $ \fBdate |./a.out out.log | cat\fP
102 Tue Oct 28 10:06:00 CET 2014
103 $ \fBcat out.log\fP
104 Tue Oct 28 10:06:00 CET 2014
105 .fi
106 .in
107 .SS プログラムのソース
108 .nf
109
110 #define _GNU_SOURCE
111 #include <fcntl.h>
112 #include <stdio.h>
113 #include <stdlib.h>
114 #include <unistd.h>
115 #include <errno.h>
116 #include <limits.h>
117
118 int
119 main(int argc, char *argv[])
120 {
121     int fd;
122     int len, slen;
123
124     if (argc != 2) {
125         fprintf(stderr, "Usage: %s <file>\en", argv[0]);
126         exit(EXIT_FAILURE);
127     }
128
129     fd = open(argv[1], O_WRONLY | O_CREAT | O_TRUNC, 0644);
130     if (fd == \-1) {
131         perror("open");
132         exit(EXIT_FAILURE);
133     }
134
135     do {
136         /*
137          * tee stdin to stdout.
138          */
139         len = tee(STDIN_FILENO, STDOUT_FILENO,
140                   INT_MAX, SPLICE_F_NONBLOCK);
141
142         if (len < 0) {
143             if (errno == EAGAIN)
144                 continue;
145             perror("tee");
146             exit(EXIT_FAILURE);
147         } else
148             if (len == 0)
149                 break;
150
151         /*
152          * Consume stdin by splicing it to a file.
153          */
154         while (len > 0) {
155             slen = splice(STDIN_FILENO, NULL, fd, NULL,
156                           len, SPLICE_F_MOVE);
157             if (slen < 0) {
158                 perror("splice");
159                 break;
160             }
161             len \-= slen;
162         }
163     } while (1);
164
165     close(fd);
166     exit(EXIT_SUCCESS);
167 }
168 .fi
169 .SH 関連項目
170 \fBsplice\fP(2), \fBvmsplice\fP(2)
171 .SH この文書について
172 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.79 の一部
173 である。プロジェクトの説明とバグ報告に関する情報は
174 http://www.kernel.org/doc/man\-pages/ に書かれている。