summaryrefslogtreecommitdiff
path: root/sponge.c
diff options
context:
space:
mode:
authorjoeyh <joeyh>2006-09-14 19:13:26 +0000
committerjoeyh <joeyh>2006-09-14 19:13:26 +0000
commit08be7808b13547b5632f9a98470ca62b1f55aeee (patch)
tree0a82fd5ba5e8d8295f91029baa2e305f9929c0f1 /sponge.c
parent14f2f08540f4bb1490ef532619ccb3d948a0d5f9 (diff)
downloadmoreutils-08be7808b13547b5632f9a98470ca62b1f55aeee.tar.gz
* spongs: Output to stdout if no file is specified, useful in a pipeline
such as: cvs diff | sponge | patch -R -p0 Closes: #387501
Diffstat (limited to 'sponge.c')
-rw-r--r--sponge.c15
1 files changed, 10 insertions, 5 deletions
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);