From 08be7808b13547b5632f9a98470ca62b1f55aeee Mon Sep 17 00:00:00 2001 From: joeyh Date: Thu, 14 Sep 2006 19:13:26 +0000 Subject: [PATCH] * spongs: Output to stdout if no file is specified, useful in a pipeline such as: cvs diff | sponge | patch -R -p0 Closes: #387501 --- debian/changelog | 5 ++++- sponge.c | 15 ++++++++++----- sponge.docbook | 2 ++ 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/debian/changelog b/debian/changelog index f10b43d..145692e 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,8 +1,11 @@ moreutils (0.18) UNRELEASED; urgency=low * mispipe.docbook: Typo. Closes: #386756 + * spongs: Output to stdout if no file is specified, useful in a pipeline + such as: cvs diff | sponge | patch -R -p0 + Closes: #387501 - -- Joey Hess Sat, 9 Sep 2006 18:46:41 -0400 + -- Joey Hess Thu, 14 Sep 2006 15:11:55 -0400 moreutils (0.17) unstable; urgency=low diff --git a/sponge.c b/sponge.c index 0389ef7..a7914ea 100644 --- a/sponge.c +++ b/sponge.c @@ -41,7 +41,7 @@ int main(int argc, char **argv) { ssize_t i = 0; int outfd; - if (argc != 2) { + if (argc > 2 || (argc == 2 && strcmp(argv[1], "-h") == 0)) { usage(); } @@ -68,10 +68,15 @@ int main(int argc, char **argv) { exit(1); } - outfd = open(argv[1], O_CREAT | O_TRUNC | O_WRONLY, 0666); - if (outfd == -1) { - fprintf(stderr, "Can't open %s: %s\n", argv[1], strerror(errno)); - exit(1); + if (argc == 2) { + outfd = open(argv[1], O_CREAT | O_TRUNC | O_WRONLY, 0666); + if (outfd == -1) { + fprintf(stderr, "Can't open %s: %s\n", argv[1], strerror(errno)); + exit(1); + } + } + else { + outfd = 1; } i = write(outfd, bufstart, bufused); diff --git a/sponge.docbook b/sponge.docbook index 674ef05..f9395a7 100644 --- a/sponge.docbook +++ b/sponge.docbook @@ -59,6 +59,8 @@ USA opening the output file. This allows for constructing pipelines that read from and write to the same file. + If no output file is specified, sponge outputs to + stdout. -- 2.39.5