diff options
author | Thomas Huth <thuth@redhat.com> | 2016-09-09 21:52:04 +0200 |
---|---|---|
committer | Alexey Kardashevskiy <aik@ozlabs.ru> | 2016-09-14 17:50:40 +1000 |
commit | 474d1d6c8a84002164d70eecf948a7eecb00a5b4 (patch) | |
tree | 6ea96493335c61fffd6ddf514d147a74ef629e67 /slof | |
parent | e0dc16c217b3d7f98165ff2c7473c9222c879354 (diff) | |
download | SLOF-474d1d6c8a84002164d70eecf948a7eecb00a5b4.zip SLOF-474d1d6c8a84002164d70eecf948a7eecb00a5b4.tar.gz SLOF-474d1d6c8a84002164d70eecf948a7eecb00a5b4.tar.bz2 |
paflof: Add a read() function to read keyboard input
The libnet code uses read() to check for keyboard input
(so that it can abort the network loading when the user
pressed ESC). So to be able to use the libnet code with
Paflof, too, we have got to provide a read() function here.
Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Diffstat (limited to 'slof')
-rw-r--r-- | slof/ppc64.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/slof/ppc64.c b/slof/ppc64.c index 7169cb0..e88b240 100644 --- a/slof/ppc64.c +++ b/slof/ppc64.c @@ -202,3 +202,29 @@ int send(int fd, const void *buf, int len, int flags) return forth_eval_pop("write"); } + +/** + * Standard read function for the libc. + * + * @param fd file descriptor (should always be 0 or 2) + * @param buf pointer to the array with the output characters + * @param len number of bytes to be read + * @return the number of bytes that have been read successfully + */ +ssize_t read(int fd, void *buf, size_t len) +{ + char *ptr = (char *)buf; + int cnt = 0; + char code; + + if (fd == 0 || fd == 2) { + while (cnt < len) { + code = forth_eval_pop("key? IF key ELSE 0 THEN"); + if (!code) + break; + ptr[cnt++] = code; + } + } + + return cnt; +} |