blob: 7c9b39e9325fb6d422448fca06aed9a86a23bd1c [file] [log] [blame]
rscb2cfc4e2003-09-30 17:47:41 +00001#include <fmt.h>
2#include "bio.h"
3
4Biobuf bout;
5
6void
7bcat(Biobuf *b, char *name)
8{
9 char buf[1000];
10 int n;
11
12 while((n = Bread(b, buf, sizeof buf)) > 0){
13 if(Bwrite(&bout, buf, n) < 0)
14 fprint(2, "writing during %s: %r\n", name);
15 }
16 if(n < 0)
17 fprint(2, "reading %s: %r\n", name);
18}
19
20int
21main(int argc, char **argv)
22{
23 int i;
24 Biobuf b, *bp;
rsc669250d2003-12-03 22:50:48 +000025 Fmt fmt;
rscb2cfc4e2003-09-30 17:47:41 +000026
27 Binit(&bout, 1, O_WRONLY);
rsc669250d2003-12-03 22:50:48 +000028 Bfmtinit(&fmt, &bout);
29 fmtprint(&fmt, "hello, world\n");
30 Bfmtflush(&fmt);
rscb2cfc4e2003-09-30 17:47:41 +000031
32 if(argc == 1){
33 Binit(&b, 0, O_RDONLY);
34 bcat(&b, "<stdin>");
35 }else{
36 for(i=1; i<argc; i++){
37 if((bp = Bopen(argv[i], O_RDONLY)) == 0){
38 fprint(2, "Bopen %s: %r\n", argv[i]);
39 continue;
40 }
41 bcat(bp, argv[i]);
42 Bterm(bp);
43 }
44 }
45 exit(0);
46}