OSDN Git Service

9496dfc2bb33f4177990593f650c83a668318a9b
[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 .\" 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 .SH Ì¾Á°
32 tee \- ¥Ñ¥¤¥×¤ÎÃæ¿È¤òÊ£À½¤¹¤ë
33 .SH ½ñ¼°
34 .nf
35 .B #define _GNU_SOURCE
36 .B #include <fcntl.h>
37
38 .BI "ssize_t tee(int " fd_in ", int " fd_out ", size_t " len \
39 ", unsigned int " flags );
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 .BR tee ()
50 ¤Ï¡¢¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿
51 .I fd_in
52 ¤¬»²¾È¤¹¤ë¥Ñ¥¤¥×¤«¤é¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿
53 .I fd_out
54 ¤¬»²¾È¤¹¤ë¥Ñ¥¤¥×¤ØºÇÂç
55 .I len
56 ¥Ð¥¤¥È¤Î¥Ç¡¼¥¿¤òÊ£À½¤¹¤ë¡£
57 ¤³¤ÎÁàºî¤Ç¤Ï¡¢Ê£À½¤µ¤ì¤ë¥Ç¡¼¥¿¤Ï
58 .I fd_in
59 ¤«¤é¤Ï¾ÃÈñ¤µ¤ì¤Ê¤¤¡£¤·¤¿¤¬¤Ã¤Æ¡¢¤³¤ì¤é¤Î¥Ç¡¼¥¿¤ò¤³¤Î¸å¤Î
60 .BR splice (2)
61 ¤Ç¥³¥Ô¡¼¤¹¤ë¤³¤È¤¬¤Ç¤­¤ë¡£
62
63 .I flags
64 ¤Ï°ìÏ¢¤Î½¤¾þ¥Õ¥é¥°¤Ç¤¢¤ê¡¢
65 .BR splice (2)
66 ¤ä
67 .BR vmsplice (2)
68 ¤È¶¦Ä̤Î̾Á°¤Ç¤¢¤ë¡£
69 .TP 1.9i
70 .B SPLICE_F_MOVE
71 ¸½ºß¤Î¤È¤³¤í
72 .BR tee ()
73 ¤Ç¤Ï²¿¤Î¸ú²Ì¤â¤Ê¤¤¡£
74 .BR splice (2)
75 »²¾È¡£
76 .TP
77 .B SPLICE_F_NONBLOCK
78 Æþ½ÐÎÏ»þ¤ËÄä»ß (block) ¤·¤Ê¤¤¡£
79 ¾ÜºÙ¤Ï
80 .BR splice (2)
81 »²¾È¡£
82 .TP
83 .B SPLICE_F_MORE
84 ¸½ºß¤Î¤È¤³¤í
85 .BR tee ()
86 ¤Ç¤Ï²¿¤Î¸ú²Ì¤â¤Ê¤¤¤¬¡¢¾­ÍèŪ¤Ë¤Ï¼ÂÁõ¤µ¤ì¤ë²ÄǽÀ­¤¬¤¢¤ë¡£
87 .BR splice (2)
88 »²¾È¡£
89 .TP
90 .B SPLICE_F_GIFT
91 .BR tee ()
92 ¤Ç¤Ï̤»ÈÍÑ¡£
93 .BR vmsplice (2)
94 »²¾È¡£
95 .SH ÊÖ¤êÃÍ
96 À®¸ù¤·¤Æ´°Î»¤¹¤ë¤È¡¢
97 .BR tee ()
98 ¤ÏÆþ½ÐÎÏ´Ö¤ÇÊ£À½¤µ¤ì¤¿¥Ð¥¤¥È¿ô¤òÊÖ¤¹¡£
99 ÊÖ¤êÃÍ 0 ¤Ï¥Ç¡¼¥¿¤ÎžÁ÷¤¬¹Ô¤ï¤ì¤Ê¤«¤Ã¤¿¤³¤È¤ò¼¨¤¹¡£
100 ¤³¤Î¾ì¹ç¡¢½èÍý¤òÄä»ß (block) ¤·¤Æ¤â̵°ÕÌ£¤Ç¤¢¤ë¡£
101 ¤Ê¤¼¤Ê¤é¡¢
102 .I fd_in
103 ¤¬»²¾È¤¹¤ë¥Ñ¥¤¥×¤Î½ñ¤­¹þ¤ß¦¤ËÀܳ¤µ¤ì¤Æ¤¤¤ë¼Ô¤¬¤¤¤Ê¤¤¤«¤é¤Ç¤¢¤ë¡£
104
105 ¥¨¥é¡¼¤Î¾ì¹ç¡¢
106 .BR tee ()
107 ¤Ï \-1 ¤òÊÖ¤·¡¢
108 .I errno
109 ¤Ë¥¨¥é¡¼¤ò¼¨¤¹ÃͤòÀßÄꤹ¤ë¡£
110 .SH ¥¨¥é¡¼
111 .TP
112 .B EINVAL
113 .I fd_in
114 ¤È
115 .I fd_out
116 ¤Î¤É¤Á¤é¤«¤¬¥Ñ¥¤¥×¤ò»²¾È¤·¤Æ¤¤¤Ê¤¤¡£¤â¤·¤¯¤Ï
117 .I fd_in
118 ¤È
119 .I fd_out
120 ¤¬Æ±¤¸¥Ñ¥¤¥×¤ò»²¾È¤·¤Æ¤¤¤ë¡£
121 .TP
122 .B ENOMEM
123 ¥á¥â¥êÉÔ­¡£
124 .SH ¥Ð¡¼¥¸¥ç¥ó
125 .BR tee ()
126 ¥·¥¹¥Æ¥à¥³¡¼¥ë¤Ï Linux 2.6.17 ¤Ç½é¤á¤ÆÅо줷¤¿¡£
127 .SH ½àµò
128 ¤³¤Î¥·¥¹¥Æ¥à¥³¡¼¥ë¤Ï Linux ¸ÇÍ­¤Ç¤¢¤ë¡£
129 .SH Ãí°Õ
130 ³µÇ°¤È¤·¤Æ¤Ï¡¢
131 .BR tee ()
132 ¤ÏÆó¤Ä¤Î¥Ñ¥¤¥×´Ö¤Ç¥Ç¡¼¥¿¤Î¥³¥Ô¡¼¤ò¹Ô¤¦¡£
133 ¤·¤«¤·¡¢¼ÂºÝ¤Ë¤Ï¼Â¥Ç¡¼¥¿¤Î¥³¥Ô¡¼¤Ï¹Ô¤ï¤ì¤Ê¤¤¡£
134 ÆâÉô¤Ç¤Ï¡¢
135 .BR tee ()
136 ¤ÏÆþÎϦ¤ËÂФ¹¤ë»²¾È¤À¤±¤òºîÀ®¤¹¤ë¤³¤È¤Ç½ÐÎϦ¤Ë¥Ç¡¼¥¿¤ò
137 Äɲ乤롣
138 .SH Îã
139 °Ê²¼¤ÎÎã¤Ï¡¢
140 .BR tee ()
141 ¥·¥¹¥Æ¥à¥³¡¼¥ë¤ò»È¤Ã¤Æ¡¢
142 ´ðËÜŪ¤Ê
143 .BR tee (1)
144 ¥×¥í¥°¥é¥à¤ò¼ÂÁõ¤·¤¿¤â¤Î¤Ç¤¢¤ë¡£
145 .nf
146
147 #define _GNU_SOURCE
148 #include <fcntl.h>
149 #include <stdio.h>
150 #include <stdlib.h>
151 #include <unistd.h>
152 #include <errno.h>
153 #include <limits.h>
154
155 int
156 main(int argc, char *argv[])
157 {
158     int fd;
159     int len, slen;
160
161     if (argc != 2) {
162         fprintf(stderr, "Usage: %s <file>\\n", argv[0]);
163         exit(EXIT_FAILURE);
164     }
165
166     fd = open(argv[1], O_WRONLY | O_CREAT | O_TRUNC, 0644);
167     if (fd == \-1) {
168         perror("open");
169         exit(EXIT_FAILURE);
170     }
171
172     do {
173         /*
174          * tee stdin to stdout.
175          */
176         len = tee(STDIN_FILENO, STDOUT_FILENO,
177                   INT_MAX, SPLICE_F_NONBLOCK);
178
179         if (len < 0) {
180             if (errno == EAGAIN)
181                 continue;
182             perror("tee");
183             exit(EXIT_FAILURE);
184         } else
185             if (len == 0)
186                 break;
187
188         /*
189          * Consume stdin by splicing it to a file.
190          */
191         while (len > 0) {
192             slen = splice(STDIN_FILENO, NULL, fd, NULL,
193                           len, SPLICE_F_MOVE);
194             if (slen < 0) {
195                 perror("splice");
196                 break;
197             }
198             len \-= slen;
199         }
200     } while (1);
201
202     close(fd);
203     exit(EXIT_SUCCESS);
204 }
205 .fi
206 .SH ´ØÏ¢¹àÌÜ
207 .BR splice (2),
208 .BR vmsplice (2),
209 .BR feature_test_macros (7)