1 #include <u.h> 2 #include <libc.h> 3 #include <bio.h> 4 5 void 6 main(int argc, char *argv[]) 7 { 8 char c; 9 int n, fd; 10 Biobuf out; 11 12 if(argc > 1){ 13 fd = open(argv[1], OREAD); 14 if(fd < 0){ 15 perror(argv[1]); 16 exits("open"); 17 } 18 }else 19 fd = 0; 20 Binit(&out, 1, OWRITE); 21 for(;;){ 22 n = read(fd, &c, 1); 23 if(n < 0){ 24 perror("read"); 25 exits("read"); 26 } 27 if(n == 0) 28 exits("eof"); 29 Bputc(&out, c); 30 if(c == '\n') 31 break; 32 } 33 exits(0); 34 } 35