2013-07-02 13:26:24 -04:00
|
|
|
/* See LICENSE file for copyright and license details. */
|
2017-07-03 17:58:49 -04:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
2014-11-13 12:29:30 -05:00
|
|
|
|
2013-07-02 13:26:24 -04:00
|
|
|
#include "util.h"
|
|
|
|
|
|
|
|
static void
|
|
|
|
usage(void)
|
|
|
|
{
|
2015-03-01 17:42:16 -05:00
|
|
|
eprintf("usage: %s file\n", argv0);
|
2013-07-02 13:26:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
2017-07-03 17:58:49 -04:00
|
|
|
char tmp[] = "/tmp/sponge-XXXXXX";
|
|
|
|
int fd, tmpfd;
|
2013-07-02 13:26:24 -04:00
|
|
|
|
2019-06-28 03:18:48 -04:00
|
|
|
ARGBEGIN {
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
} ARGEND
|
2013-07-02 13:26:24 -04:00
|
|
|
|
2014-11-13 12:29:30 -05:00
|
|
|
if (argc != 1)
|
2013-07-02 13:26:24 -04:00
|
|
|
usage();
|
|
|
|
|
2017-07-03 17:58:49 -04:00
|
|
|
if ((tmpfd = mkstemp(tmp)) < 0)
|
|
|
|
eprintf("mkstemp:");
|
|
|
|
unlink(tmp);
|
|
|
|
if (concat(0, "<stdin>", tmpfd, "<tmpfile>") < 0)
|
|
|
|
return 1;
|
|
|
|
if (lseek(tmpfd, 0, SEEK_SET) < 0)
|
|
|
|
eprintf("lseek:");
|
2013-07-02 13:26:24 -04:00
|
|
|
|
2017-07-03 17:58:49 -04:00
|
|
|
if ((fd = creat(argv[0], 0666)) < 0)
|
|
|
|
eprintf("creat %s:", argv[0]);
|
|
|
|
if (concat(tmpfd, "<tmpfile>", fd, argv[0]) < 0)
|
|
|
|
return 1;
|
2013-07-02 13:26:24 -04:00
|
|
|
|
2017-07-03 17:58:49 -04:00
|
|
|
return 0;
|
2013-07-02 13:26:24 -04:00
|
|
|
}
|