aboutsummaryrefslogtreecommitdiff
path: root/fsub.c
diff options
context:
space:
mode:
Diffstat (limited to 'fsub.c')
-rw-r--r--fsub.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/fsub.c b/fsub.c
index 4bc394f..d1863a7 100644
--- a/fsub.c
+++ b/fsub.c
@@ -46,7 +46,7 @@ static void fsub(char *, pcre2_match_data *, pcre2_code *, char *);
int
main(int argc, char *argv[])
{
- int fd, fd2, ec, opt;
+ int fd = 0, fd2, ec, opt;
char *needle, *haystack, *repl,
*argv0 = argv[0],
*optstr = "dim",
@@ -89,7 +89,10 @@ main(int argc, char *argv[])
}
needle = argv[0];
- fd = loadfile(&repl, argv[1]);
+ if (streq(argv[1], "-"))
+ repl = stdio_to_string();
+ else
+ fd = loadfile(&repl, argv[1]);
rx = pcre2_compile((PCRE2_SPTR) needle, PCRE2_ZERO_TERMINATED,
rx_opts, &ec, &eo, NULL);
if (rx == NULL) {
@@ -115,7 +118,9 @@ main(int argc, char *argv[])
pcre2_match_data_free(mdata);
pcre2_code_free(rx);
- close(fd);
+
+ if (!streq(argv[1], "-"))
+ close(fd);
return rv;
}