2013-05-16 23:03:38 +00:00
|
|
|
/*
|
|
|
|
* Raspberry Pi support library for the ACK
|
|
|
|
* © 2013 David Given
|
|
|
|
* This file is redistributable under the terms of the 3-clause BSD license.
|
|
|
|
* See the file 'Copying' in the root of the distribution for the full text.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <unistd.h>
|
2013-05-30 22:19:55 +00:00
|
|
|
#include <termios.h>
|
2013-05-16 23:03:38 +00:00
|
|
|
#include "libsys.h"
|
|
|
|
|
2013-05-30 22:19:55 +00:00
|
|
|
int _sys_ttyflags = ONLCR | INLCR | ECHO;
|
|
|
|
|
2013-05-16 23:03:38 +00:00
|
|
|
void _sys_write_tty(char c)
|
|
|
|
{
|
|
|
|
_sys_rawwrite(c);
|
2013-05-30 22:19:55 +00:00
|
|
|
if ((c == '\n') && (_sys_ttyflags & ONLCR))
|
2013-05-16 23:03:38 +00:00
|
|
|
_sys_rawwrite('\r');
|
|
|
|
}
|
|
|
|
|
2018-06-23 11:05:27 +00:00
|
|
|
ssize_t write(int fd, void* buffer, size_t count)
|
2013-05-16 23:03:38 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
char* p = buffer;
|
|
|
|
|
|
|
|
/* We're only allowed to write to fd 0, 1 or 2. */
|
|
|
|
|
|
|
|
if ((fd < 0) || (fd > 2))
|
|
|
|
{
|
|
|
|
errno = EBADF;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Write all data. */
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
while (i < count)
|
|
|
|
{
|
|
|
|
_sys_write_tty(*p++);
|
|
|
|
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* No failures. */
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|