aboutsummaryrefslogtreecommitdiff
path: root/src/libbio/bcat.c
blob: 7c9b39e9325fb6d422448fca06aed9a86a23bd1c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <fmt.h>
#include "bio.h"

Biobuf bout;

void
bcat(Biobuf *b, char *name)
{
	char buf[1000];
	int n;

	while((n = Bread(b, buf, sizeof buf)) > 0){
		if(Bwrite(&bout, buf, n) < 0)
			fprint(2, "writing during %s: %r\n", name);
	}
	if(n < 0)
		fprint(2, "reading %s: %r\n", name);	
}

int
main(int argc, char **argv)
{
	int i;
	Biobuf b, *bp;
	Fmt fmt;

	Binit(&bout, 1, O_WRONLY);
	Bfmtinit(&fmt, &bout);
	fmtprint(&fmt, "hello, world\n");
	Bfmtflush(&fmt);

	if(argc == 1){
		Binit(&b, 0, O_RDONLY);
		bcat(&b, "<stdin>");
	}else{
		for(i=1; i<argc; i++){
			if((bp = Bopen(argv[i], O_RDONLY)) == 0){
				fprint(2, "Bopen %s: %r\n", argv[i]);
				continue;
			}
			bcat(bp, argv[i]);
			Bterm(bp);
		}
	}
	exit(0);
}