sbase/tee.c
FRIGN ec8246bbc6 Un-boolify sbase
It actually makes the binaries smaller, the code easier to read
(gems like "val == true", "val == false" are gone) and actually
predictable in the sense of that we actually know what we're
working with (one bitwise operator was quite adventurous and
should now be fixed).

This is also more consistent with the other suckless projects
around which don't use boolean types.
2014-11-14 10:54:20 +00:00

52 lines
885 B
C

/* See LICENSE file for copyright and license details. */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "util.h"
static void
usage(void)
{
eprintf("usage: %s [-a] [file...]\n", argv0);
}
int
main(int argc, char *argv[])
{
int aflag = 0;
char buf[BUFSIZ];
int i, nfps;
size_t n;
FILE **fps = NULL;
ARGBEGIN {
case 'a':
aflag = 1;
break;
default:
usage();
} ARGEND;
nfps = argc + 1;
if (!(fps = calloc(nfps, sizeof *fps)))
eprintf("calloc:");
for (i = 0; argc > 0; argc--, argv++, i++)
if (!(fps[i] = fopen(*argv, aflag ? "a" : "w")))
eprintf("fopen %s:", *argv);
fps[i] = stdout;
while ((n = fread(buf, 1, sizeof buf, stdin)) > 0) {
for (i = 0; i < nfps; i++) {
if (fwrite(buf, 1, n, fps[i]) != n)
eprintf("%s: write error:", buf);
}
}
if (ferror(stdin))
eprintf("<stdin>: read error:");
free(fps);
return 0;
}