sbase

suckless unix tools
git clone git://git.2f30.org/sbase
Log | Files | Refs | README | LICENSE

commit 60731fb6e8108919d7636716f615fd3b8670d7ae
parent eadefcf0f8e4d329e8987745e1ed32d354cfa8b2
Author: David Galos <galosd83@students.rowan.edu>
Date:   Tue,  2 Jul 2013 13:26:24 -0400

actually add the .c and .1 files

Diffstat:
Asponge.1 | 15+++++++++++++++
Asponge.c | 40++++++++++++++++++++++++++++++++++++++++
2 files changed, 55 insertions(+), 0 deletions(-)

diff --git a/sponge.1 b/sponge.1 @@ -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 @@ -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\n"); +} + +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; +}