[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [mini-os master] mini-os: minimal implementations of some termios functions



commit c96c22f1d94d254eb8302ae5f4e201a98451232e
Author:     Simon Waterman <watermansrdev@xxxxxxxxx>
AuthorDate: Sun Jun 25 23:02:08 2017 +0100
Commit:     Wei Liu <wei.liu2@xxxxxxxxxx>
CommitDate: Tue Jul 4 14:06:29 2017 +0100

    mini-os: minimal implementations of some termios functions
    
    Add minimal implementation of termios functions so that a console
    can be configured in raw mode if an application requires it.
    
    Signed-off-by: Simon Waterman <watermansrdev@xxxxxxxxx>
    Acked-by: Wei Liu <wei.liu2@xxxxxxxxxx>
---
 lib/sys.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 77 insertions(+), 2 deletions(-)

diff --git a/lib/sys.c b/lib/sys.c
index 1420722..b173bc8 100644
--- a/lib/sys.c
+++ b/lib/sys.c
@@ -32,6 +32,7 @@
 #include <xenbus.h>
 #include <xenstore.h>
 #include <poll.h>
+#include <termios.h>
 
 #include <sys/types.h>
 #include <sys/unistd.h>
@@ -1436,6 +1437,82 @@ int nice(int inc)
     return 0;
 }
 
+/* Limited termios terminal settings support */
+const struct termios default_termios = {0,             /* iflag */
+                                        OPOST | ONLCR, /* oflag */
+                                        0,             /* lflag */
+                                        CREAD | CS8,   /* cflag */
+                                        {}};           /* cc */
+
+int tcsetattr(int fildes, int action, const struct termios *tios)
+{
+    if (fildes < 0 || fildes >= NOFILE) {
+        errno = EBADF;
+        return -1;
+    }
+
+    if (files[fildes].type != FTYPE_CONSOLE) {
+        errno = ENOTTY;
+        return -1;
+    }
+
+    if (tios == NULL) {
+        errno = EINVAL;
+        return -1;
+    }
+
+    switch (action) {
+        case TCSANOW:
+        case TCSADRAIN:
+        case TCSAFLUSH:
+            break;
+        default:
+            errno = EINVAL;
+            return -1;
+    }
+
+    if (tios->c_oflag & OPOST)
+        files[fildes].cons.dev->is_raw = false;
+    else
+        files[fildes].cons.dev->is_raw = true;
+
+    return 0;
+}
+
+int tcgetattr(int fildes, struct termios *tios)
+{
+    if (fildes < 0 || fildes >= NOFILE) {
+        errno = EBADF;
+        return -1;
+    }
+
+    if (files[fildes].type != FTYPE_CONSOLE) {
+        errno = ENOTTY;
+        return -1;
+    }
+
+    if (tios == NULL) {
+        errno = EINVAL;
+        return -1;
+    }
+
+    memcpy(tios, &default_termios, sizeof(struct termios));
+
+    if (files[fildes].cons.dev->is_raw)
+        tios->c_oflag &= ~OPOST;
+
+    return 0;
+}
+
+void cfmakeraw(struct termios *tios)
+{
+    tios->c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP
+                       | INLCR | IGNCR | ICRNL | IXON);
+    tios->c_oflag &= ~OPOST;
+    tios->c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
+    tios->c_cflag &= ~(CSIZE | PARENB);
+    tios->c_cflag |= CS8;
+}
 
 /* Not supported by FS yet.  */
 unsupported_function_crash(link);
@@ -1472,8 +1549,6 @@ unsupported_function_crash(waitpid);
 unsupported_function_crash(wait);
 unsupported_function_crash(lockf);
 unsupported_function_crash(sysconf);
-unsupported_function(int, tcsetattr, -1);
-unsupported_function(int, tcgetattr, 0);
 unsupported_function(int, grantpt, -1);
 unsupported_function(int, unlockpt, -1);
 unsupported_function(char *, ptsname, NULL);
--
generated by git-patchbot for /home/xen/git/mini-os.git#master

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxx
https://lists.xenproject.org/xen-changelog

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.