[SLOF] [PATCH 06/11] paflof: Add a read() function to read keyboard input

Thomas Huth thuth at redhat.com
Sat Sep 10 05:52:04 AEST 2016


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 at redhat.com>
---
 slof/ppc64.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

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;
+}
-- 
1.8.3.1



More information about the SLOF mailing list