2013-07-02 17:26:24 +00:00
|
|
|
/* See LICENSE file for copyright and license details. */
|
2017-07-03 21:58:49 +00:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
2014-11-13 17:29:30 +00:00
|
|
|
|
2013-07-02 17:26:24 +00:00
|
|
|
#include "util.h"
|
|
|
|
|
|
|
|
static void
|
|
|
|
usage(void)
|
|
|
|
{
|
2015-03-01 22:42:16 +00:00
|
|
|
eprintf("usage: %s file\n", argv0);
|
2013-07-02 17:26:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
2017-07-03 21:58:49 +00:00
|
|
|
char tmp[] = "/tmp/sponge-XXXXXX";
|
|
|
|
int fd, tmpfd;
|
2013-07-02 17:26:24 +00:00
|
|
|
|
2017-08-05 21:50:39 +00:00
|
|
|
argv0 = *argv, argv0 ? (argc--, argv++) : (void *)0;
|
2013-07-02 17:26:24 +00:00
|
|
|
|
2014-11-13 17:29:30 +00:00
|
|
|
if (argc != 1)
|
2013-07-02 17:26:24 +00:00
|
|
|
usage();
|
|
|
|
|
2017-07-03 21:58:49 +00: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 17:26:24 +00:00
|
|
|
|
2017-07-03 21:58:49 +00: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 17:26:24 +00:00
|
|
|
|
2017-07-03 21:58:49 +00:00
|
|
|
return 0;
|
2013-07-02 17:26:24 +00:00
|
|
|
}
|