actually add the .c and .1 files
This commit is contained in:
parent
eadefcf0f8
commit
60731fb6e8
15
sponge.1
Normal file
15
sponge.1
Normal file
|
@ -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.
|
40
sponge.c
Normal file
40
sponge.c
Normal file
|
@ -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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user