summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sponge.c12
-rw-r--r--sponge.docbook18
2 files changed, 27 insertions, 3 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);
diff --git a/sponge.docbook b/sponge.docbook
index 07a2645..a892837 100644
--- a/sponge.docbook
+++ b/sponge.docbook
@@ -48,7 +48,7 @@ USA
<refsynopsisdiv>
<cmdsynopsis>
- <command>sed '...' file | grep '...' | sponge file</command>
+ <command>sed '...' file | grep '...' | sponge [-a] file</command>
</cmdsynopsis>
</refsynopsisdiv>
@@ -72,6 +72,22 @@ USA
stdout.</para>
</refsect1>
+
+ <refsect1>
+ <title>OPTIONS</title>
+
+ <variablelist>
+
+ <varlistentry>
+ <term><option>-a</option></term>
+ <listitem>
+ <para>Append the output to the specified file
+ instead possible backup and re-creation.</para>
+ </listitem>
+ </varlistentry>
+
+ </variablelist>
+ </refsect1>
<refsect1>
<title>AUTHOR</title>