2007-02-20 00:31:54 +00:00
|
|
|
/* $Source$
|
|
|
|
* $State$
|
|
|
|
* $Revision$
|
|
|
|
*/
|
|
|
|
|
2007-02-20 00:25:12 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <errno.h>
|
2007-04-21 22:59:42 +00:00
|
|
|
#include <unistd.h>
|
2007-02-20 00:25:12 +00:00
|
|
|
#include "libsys.h"
|
|
|
|
|
2018-06-23 10:59:40 +00:00
|
|
|
ssize_t read(int fd, void* buffer, size_t count)
|
2007-02-20 00:25:12 +00:00
|
|
|
{
|
|
|
|
char i;
|
|
|
|
|
|
|
|
/* We're only allowed to read from fd 0, 1 or 2. */
|
|
|
|
|
2007-04-21 22:59:42 +00:00
|
|
|
if ((fd < 0) || (fd > 2))
|
|
|
|
{
|
|
|
|
errno = EBADF;
|
|
|
|
return -1;
|
|
|
|
}
|
2007-02-20 00:25:12 +00:00
|
|
|
|
|
|
|
/* Empty buffer? */
|
|
|
|
|
2007-04-21 22:59:42 +00:00
|
|
|
if (count == 0)
|
2007-02-20 00:25:12 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Read one byte. */
|
|
|
|
|
|
|
|
i = _sys_rawread();
|
2007-04-21 22:59:42 +00:00
|
|
|
#if 0
|
2007-02-20 00:25:12 +00:00
|
|
|
if ((i == '\r') && !(_sys_ttyflags & RAW))
|
|
|
|
i = '\n';
|
|
|
|
if (_sys_ttyflags & ECHO)
|
|
|
|
_sys_write_tty(i);
|
2007-04-21 22:59:42 +00:00
|
|
|
#endif
|
|
|
|
if (i == '\r')
|
|
|
|
i = '\n';
|
|
|
|
_sys_write_tty(i);
|
2007-02-20 00:25:12 +00:00
|
|
|
|
2007-04-21 22:59:42 +00:00
|
|
|
*(char*)buffer = i;
|
|
|
|
return 1;
|
2007-02-20 00:25:12 +00:00
|
|
|
}
|