ack/plat/cpm/libsys/read.c
2007-04-27 22:42:41 +00:00

39 lines
536 B
C

/* $Source$
* $State$
* $Revision$
*/
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include <cpm.h>
int read(int fd, void* buffer, size_t count)
{
char i;
/* We're only allowed to read from fd 0, 1 or 2. */
if ((fd < 0) || (fd > 2))
{
errno = EBADF;
return -1;
}
/* Empty buffer? */
if (count == 0)
return 0;
/* Read one byte. */
cpm_bc_register = CPM_BDOS_CONSOLE_INPUT;
cpm_bdos();
if (cpm_a_register == '\r')
cpm_a_register = '\n';
*(char*)buffer = cpm_a_register;
return 1;
}