2013-07-02 17:26:24 +00:00
|
|
|
/* See LICENSE file for copyright and license details. */
|
|
|
|
#include <stdio.h>
|
2014-11-13 17:29:30 +00:00
|
|
|
|
2013-07-02 17:26:24 +00:00
|
|
|
#include "text.h"
|
|
|
|
#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[])
|
|
|
|
{
|
|
|
|
FILE *fp, *tmpfp;
|
2015-05-24 23:33:19 +00:00
|
|
|
int ret = 0;
|
2013-07-02 17:26:24 +00:00
|
|
|
|
2015-04-24 21:54:17 +00:00
|
|
|
argv0 = argv[0], argc--, argv++;
|
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();
|
|
|
|
|
2014-11-13 17:29:30 +00:00
|
|
|
if (!(tmpfp = tmpfile()))
|
2013-07-02 17:26:24 +00:00
|
|
|
eprintf("tmpfile:");
|
|
|
|
concat(stdin, "<stdin>", tmpfp, "<tmpfile>");
|
|
|
|
rewind(tmpfp);
|
|
|
|
|
2014-11-13 17:29:30 +00:00
|
|
|
if (!(fp = fopen(argv[0], "w")))
|
2014-11-16 13:20:20 +00:00
|
|
|
eprintf("fopen %s:", argv[0]);
|
2013-07-02 17:26:24 +00:00
|
|
|
concat(tmpfp, "<tmpfile>", fp, argv[0]);
|
|
|
|
|
2015-05-24 23:33:19 +00:00
|
|
|
ret |= fshut(fp, argv[0]) | fshut(tmpfp, "<tmpfile>");
|
|
|
|
|
|
|
|
return ret;
|
2013-07-02 17:26:24 +00:00
|
|
|
}
|