[hackers] [sbase] actually add the .c and .1 files || David Galos
commit 60731fb6e8108919d7636716f615fd3b8670d7ae
Author: David Galos <galosd83_AT_students.rowan.edu>
Date: Tue Jul 2 13:26:24 2013 -0400
actually add the .c and .1 files
diff --git a/sponge.1 b/sponge.1
new file mode 100644
index 0000000..a33d81a
--- /dev/null
+++ b/sponge.1
_AT_@ -0,0 +1,15 @@
+.TH SPONGE 1 sbase\-VERSION
+.SH NAME
+sponge \- soak up standard input and write to a file
+.SH SYNOPSIS
+.B sponge
+.IR file
+.SH DESCRIPTION
+.B sponge
+reads stdin completely, then writes the saved contents to
+.IR file .
+This makes it possible to easily create pipes which read from and write to
+the same file.
+
+If the given file is a symbolic link, it writes to the links's destination
+instead.
diff --git a/sponge.c b/sponge.c
new file mode 100644
index 0000000..8084166
--- /dev/null
+++ b/sponge.c
_AT_@ -0,0 +1,40 @@
+/* See LICENSE file for copyright and license details. */
+#include <stdio.h>
+
+#include "text.h"
+#include "util.h"
+
+static void
+usage(void)
+{
+ eprintf("usage: sponge file
");
+}
+
+int
+main(int argc, char *argv[])
+{
+ FILE *fp, *tmpfp;
+
+ ARGBEGIN {
+ default:
+ usage();
+ } ARGEND;
+
+ if(argc != 1)
+ usage();
+
+ if(!(tmpfp = tmpfile()))
+ eprintf("tmpfile:");
+
+ concat(stdin, "<stdin>", tmpfp, "<tmpfile>");
+ rewind(tmpfp);
+
+ if(!(fp = fopen(argv[0], "w")))
+ eprintf("sponge: '%s':", argv[0]);
+ concat(tmpfp, "<tmpfile>", fp, argv[0]);
+
+ fclose(fp);
+ fclose(tmpfp);
+
+ return 0;
+}
Received on Tue Jul 02 2013 - 19:26:27 CEST
This archive was generated by hypermail 2.3.0
: Tue Jul 02 2013 - 19:36:21 CEST