
// a restricted version of the cat(1) command

#include <unistd.h>
#include <assert.h>
#include <stdlib.h>
#include <errno.h>
#include <err.h>

#define SIZE 200

int main ()
{
	char buff[SIZE];
	ssize_t ret;
	ssize_t ret2;

	while (1)
	{
		ret = read (0, buff, SIZE);
		// error
		if (ret == -1)
		{
			//write (2, strerror (errno), strlen (strerror (errno)));
			//exit (1);
			err (1, "error!!");
			// mycat: error!!: No such file or directoery
		}

		// end of file
		if (ret == 0)
		{
			break;
		}

		// we have data to work on!
		ret2 = write (1, buff, ret);
		// error
		if (ret2 == -1)
		{
			// deal with the error
			exit (1);
		}
		if (ret2 != ret)
		{
			// deal with the error
			exit (1);
		}
	}

	assert (ret == 0);
	exit (0);
}
