summaryrefslogtreecommitdiff
path: root/sponge.c
diff options
context:
space:
mode:
Diffstat (limited to 'sponge.c')
-rw-r--r--sponge.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/sponge.c b/sponge.c
index 969703f..61e6a42 100644
--- a/sponge.c
+++ b/sponge.c
@@ -42,7 +42,8 @@
char *tmpname = NULL;
void usage() {
- printf("sponge <file>: soak up all input from stdin and write it to <file>\n");
+ printf("sponge [-a] <file>: soak up all input from stdin and write it "
+ "to <file>\n");
exit(0);
}
@@ -278,6 +279,12 @@ int main (int argc, char **argv) {
ssize_t i = 0;
size_t mem_available = default_sponge_size();
int tmpfile_used=0;
+ int append=0;
+
+ if ((argc == 3) && (!strcmp(argv[1], "-a"))) {
+ append = 1;
+ argc--, argv++;
+ }
if (argc > 2 || (argc == 2 && strcmp(argv[1], "-h") == 0)) {
usage();
@@ -342,6 +349,7 @@ int main (int argc, char **argv) {
/* If it's a regular file, or does not yet exist,
* attempt a fast rename of the temp file. */
if (((exists &&
+ !append &&
S_ISREG(statbuf.st_mode) &&
! S_ISLNK(statbuf.st_mode)
) || ! exists) &&
@@ -350,7 +358,7 @@ int main (int argc, char **argv) {
}
else {
/* Fall back to slow copy. */
- outfile = fopen(outname, "w");
+ outfile = fopen(outname, append ? "a" : "w");
if (!outfile) {
perror("error opening output file");
exit(1);