(wrong string) ée

From: <git_AT_suckless.org>
Date: Wed, 31 May 2017 21:14:09 +0200 (CEST)

commit d5f9bf804180f50d1a025b3cf70e12238c79cfb3
Author: Mattias Andrée <maandree_AT_kth.se>
AuthorDate: Thu May 25 19:16:08 2017 +0200
Commit: Mattias Andrée <maandree_AT_kth.se>
CommitDate: Thu May 25 19:16:08 2017 +0200

    Add blind-tee
    
    Signed-off-by: Mattias Andrée <maandree_AT_kth.se>

diff --git a/Makefile b/Makefile
index 56b4ba4..bd0ecc7 100644
--- a/Makefile
+++ b/Makefile
_AT_@ -35,6 +35,7 @@ BIN =\
         blind-skip-pattern\
         blind-split\
         blind-stack\
+ blind-tee\
         blind-time-blur\
         blind-to-image\
         blind-to-named\
diff --git a/README b/README
index 7a54d51..0f89fa7 100644
--- a/README
+++ b/README
_AT_@ -114,6 +114,9 @@ UTILITIES
        blind-stack(1)
               Overlay videos
 
+ blind-tee(1)
+ /dev/fd/ aware tee(1) implementation
+
        blind-time-blur(1)
               Draw new frames on top of old frames with partial alpha
 
diff --git a/man/blind-from-named.1 b/man/blind-from-named.1
index afede12..b98c2d2 100644
--- a/man/blind-from-named.1
+++ b/man/blind-from-named.1
_AT_@ -58,7 +58,7 @@ input to the process, like inverse multiplexing.
 .SH SEE ALSO
 .BR blind (7),
 .BR blind-to-named (1),
-.BR tee (1)
+.BR blind-tee (1)
 .SH AUTHORS
 Mattias Andrée
 .RI < maandree_AT_kth.se >
diff --git a/man/blind-tee.1 b/man/blind-tee.1
new file mode 100644
index 0000000..4b10b83
--- /dev/null
+++ b/man/blind-tee.1
_AT_@ -0,0 +1,28 @@
+.TH BLIND-TEE 1 blind
+.SH NAME
+blind-tee - /dev/fd/ aware tee(1) implementation
+.SH SYNOPSIS
+.B blind-tee
+.RI [ file \ ...]
+.SH DESCRIPTION
+.B blind-tee
+reads stdin and writes its input to stdout and to all
+.IR file s.
+.P
+Files are opened in truncate mode, file descriptors
+specified via their /dev/fd/ path are not reopened
+but used directly.
+.SH RATIONALE
+There are situations where opening files in /dev/fd/
+creates problems. Popular
+.BR tee (1),
+implementations do not treat files in /dev/fd/
+especially.
+.SH SEE ALSO
+.BR blind (7),
+.BR blind-to-named (1),
+.BR blind-from-named (1),
+.BR tee (1)
+.SH AUTHORS
+Mattias Andrée
+.RI < maandree_AT_kth.se >
diff --git a/man/blind-to-named.1 b/man/blind-to-named.1
index 5688a5d..b01f267 100644
--- a/man/blind-to-named.1
+++ b/man/blind-to-named.1
_AT_@ -33,7 +33,7 @@ input to the process, like inverse multiplexing.
 .SH SEE ALSO
 .BR blind (7),
 .BR blind-from-named (1),
-.BR tee (1)
+.BR blind-tee (1)
 .SH AUTHORS
 Mattias Andrée
 .RI < maandree_AT_kth.se >
diff --git a/man/blind.7 b/man/blind.7
index f8c4dd0..75f244a 100644
--- a/man/blind.7
+++ b/man/blind.7
_AT_@ -127,6 +127,11 @@ Split a video, by frame, into multiple videos
 .BR blind-stack (1)
 Overlay videos
 .TP
+.BR blind-tee (1)
+/dev/fd/ aware
+.BR tee (1)
+implementation
+.TP
 .BR blind-time-blur (1)
 Draw new frames on top of old frames with partial alpha
 .TP
diff --git a/src/blind-tee.c b/src/blind-tee.c
new file mode 100644
index 0000000..9699d8c
--- /dev/null
+++ b/src/blind-tee.c
_AT_@ -0,0 +1,52 @@
+/* See LICENSE file for copyright and license details. */
+#include "common.h"
+
+USAGE("[file ...]")
+
+#if !defined(PIPE_BUF)
+# define PIPE_BUF BUFSIZ
+#endif
+
+int
+main(int argc, char *argv[])
+{
+ char buf[PIPE_BUF];
+ int *fds = alloca(argc * sizeof(*fds));
+ size_t i, n = 0, done;
+ ssize_t r, w, *ps;
+
+ UNOFLAGS(0);
+
+ fds[n++] = STDOUT_FILENO;
+ while (argc--)
+ fds[n++] = eopen(*argv++, O_WRONLY | O_CREAT | O_TRUNC, 0666);
+
+ ps = alloca(n * sizeof(*ps));
+
+ while (n) {
+ memset(ps, 0, n * sizeof(*ps));
+ r = read(STDIN_FILENO, buf, sizeof(buf));
+ if (r < 0)
+ eprintf("read <stdin>:");
+ if (!r)
+ break;
+ for (done = 0; done < n;) {
+ for (i = 0; i < n; i++) {
+ if (ps[i] == r)
+ continue;
+ w = write(fds[i], buf + ps[i], r - ps[i]);
+ if (w < 0) {
+ close(fds[i]);
+ n--;
+ memmove(fds + i, fds + i + 1, (n - i) * sizeof(*fds));
+ memmove(ps + i, ps + i + 1, (n - i) * sizeof(*ps));
+ }
+ ps[i] += w;
+ if (ps[i] == r)
+ done++;
+ }
+ }
+ }
+
+ return 0;
+}
Received on Wed May 31 2017 - 21:14:09 CEST

This archive was generated by hypermail 2.3.0 : Wed May 31 2017 - 21:24:17 CEST