OSDN Git Service

(split) LDP: Release pages for LDP v3.39.
[linuxjm/LDP_man-pages.git] / release / 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 .\"*******************************************************************
27 .\"
28 .\" This file was generated with po4a. Translate the source file.
29 .\"
30 .\"*******************************************************************
31 .TH TEE 2 2009\-09\-15 Linux "Linux Programmer's Manual"
32 .SH 名前
33 tee \- パイプの中身を複製する
34 .SH 書式
35 .nf
36 \fB#define _GNU_SOURCE\fP         /* feature_test_macros(7) 参照 */
37 \fB#include <fcntl.h>\fP
38
39 \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
40 .fi
41 .\" Return type was long before glibc 2.7
42 .SH 説明
43 .\" Example programs http://brick.kernel.dk/snaps
44 .\"
45 .\"
46 .\" add a "tee(in, out1, out2)" system call that duplicates the pages
47 .\" (again, incrementing their reference count, not copying the data) from
48 .\" one pipe to two other pipes.
49 \fBtee\fP()  は、ファイルディスクリプタ \fIfd_in\fP が参照するパイプからファイルディスクリプタ \fIfd_out\fP が参照するパイプへ最大
50 \fIlen\fP バイトのデータを複製する。 この操作では、複製されるデータは \fIfd_in\fP からは消費されない。したがって、これらのデータをこの後の
51 \fBsplice\fP(2)  でコピーすることができる。
52
53 \fIflags\fP は一連の修飾フラグであり、 \fBsplice\fP(2)  や \fBvmsplice\fP(2)  と共通の名前である。
54 .TP  1.9i
55 \fBSPLICE_F_MOVE\fP
56 現在のところ \fBtee\fP()  では何の効果もない。 \fBsplice\fP(2)  参照。
57 .TP 
58 \fBSPLICE_F_NONBLOCK\fP
59 入出力で停止 (block) しない。詳細は \fBsplice\fP(2)  参照。
60 .TP 
61 \fBSPLICE_F_MORE\fP
62 現在のところ \fBtee\fP()  では何の効果もないが、将来的には実装される可能性がある。 \fBsplice\fP(2)  参照。
63 .TP 
64 \fBSPLICE_F_GIFT\fP
65 \fBtee\fP()  では未使用。 \fBvmsplice\fP(2)  参照。
66 .SH 返り値
67 成功して完了すると、 \fBtee\fP()  は入出力間で複製されたバイト数を返す。 返り値 0 はデータの転送が行われなかったことを示す。
68 この場合、処理を停止 (block) しても無意味である。 なぜなら、 \fIfd_in\fP
69 が参照するパイプの書き込み側に接続されている者がいないからである。
70
71 エラーの場合、 \fBtee\fP()  は \-1 を返し、 \fIerrno\fP にエラーを示す値を設定する。
72 .SH エラー
73 .TP 
74 \fBEINVAL\fP
75 \fIfd_in\fP と \fIfd_out\fP のどちらかがパイプを参照していない。もしくは \fIfd_in\fP と \fIfd_out\fP
76 が同じパイプを参照している。
77 .TP 
78 \fBENOMEM\fP
79 メモリ不足。
80 .SH バージョン
81 \fBtee\fP()  システムコールは Linux 2.6.17 で初めて登場した。
82 .SH 準拠
83 このシステムコールは Linux 固有である。
84 .SH 注意
85 概念としては、 \fBtee\fP()  は二つのパイプ間でデータのコピーを行う。 しかし、実際には実データのコピーは行われない。 内部では、
86 \fBtee\fP()  は入力側に対する参照だけを作成することで出力側にデータを 追加する。
87 .SH 例
88 以下の例は、 \fBtee\fP()  システムコールを使って、 基本的な \fBtee\fP(1)  プログラムを実装したものである。
89 .nf
90
91 #define _GNU_SOURCE
92 #include <fcntl.h>
93 #include <stdio.h>
94 #include <stdlib.h>
95 #include <unistd.h>
96 #include <errno.h>
97 #include <limits.h>
98
99 int
100 main(int argc, char *argv[])
101 {
102     int fd;
103     int len, slen;
104
105     if (argc != 2) {
106         fprintf(stderr, "Usage: %s <file>\en", argv[0]);
107         exit(EXIT_FAILURE);
108     }
109
110     fd = open(argv[1], O_WRONLY | O_CREAT | O_TRUNC, 0644);
111     if (fd == \-1) {
112         perror("open");
113         exit(EXIT_FAILURE);
114     }
115
116     do {
117         /*
118          * tee stdin to stdout.
119          */
120         len = tee(STDIN_FILENO, STDOUT_FILENO,
121                   INT_MAX, SPLICE_F_NONBLOCK);
122
123         if (len < 0) {
124             if (errno == EAGAIN)
125                 continue;
126             perror("tee");
127             exit(EXIT_FAILURE);
128         } else
129             if (len == 0)
130                 break;
131
132         /*
133          * Consume stdin by splicing it to a file.
134          */
135         while (len > 0) {
136             slen = splice(STDIN_FILENO, NULL, fd, NULL,
137                           len, SPLICE_F_MOVE);
138             if (slen < 0) {
139                 perror("splice");
140                 break;
141             }
142             len \-= slen;
143         }
144     } while (1);
145
146     close(fd);
147     exit(EXIT_SUCCESS);
148 }
149 .fi
150 .SH 関連項目
151 \fBsplice\fP(2), \fBvmsplice\fP(2)