#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>

// Needed on mingw/win32
//
// usage: bcat.exe FILE | videoshow ... -stdin

main(int argc, char *argv[])
	{
	unsigned char buffer[32768];
	int i,n;
	int out;
	unsigned int total=0;
	int fd;

	fd = open(argv[1],O_RDONLY|O_BINARY);

	while(1) {
	   n = read(fd,buffer,32768);
	   if (n <= 0) break;

	   // why do I need to do this???
	   for(i=0; i<n; ++i) if (buffer[i]==26) buffer[i]=27;

	   out=0;
	   while (n>0) {
	      int m = write(1,buffer+out,n);
	      if (m<0) { break;}
	      n -= m;
	      out += m; total+= m;
	      }
	   }

	fprintf(stderr,"Piped %d bytes\n",total);
	}
