blob: d3030cd84a323b5dd52af08661c918b59ced910b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
/* ISC license. */
#include <unistd.h>
#include <skalibs/posixplz.h>
#include <skalibs/strerr.h>
#include <skalibs/djbunix.h>
#include <skalibs/exec.h>
#define USAGE "seekablepipe tempfile prog..."
#define N 8192
int main (int argc, char const *const *argv)
{
int fdr, fdw ;
PROG = "seekablepipe" ;
if (argc < 3) strerr_dieusage(100, USAGE) ;
fdw = open_trunc(argv[1]) ;
if (fdw < 0)
strerr_diefu2sys(111, "create temporary ", argv[1]) ;
fdr = open_readb(argv[1]) ;
if (fdr < 0)
strerr_diefu3sys(111, "open ", argv[1], " for reading") ;
unlink_void(argv[1]) ;
if (ndelay_off(fdw) < 0)
strerr_diefu1sys(111, "set fdw blocking") ;
if (fd_cat(0, fdw) < 0)
strerr_diefu1sys(111, "read from stdin") ;
close(fdw) ;
if (fd_move(0, fdr) < 0)
strerr_diefu1sys(111, "move temporary file descriptor") ;
xexec(argv+2) ;
}
|