Usermode/libc - Fix edge case crash with realloc on last block
[tpg/acess2.git] / Usermode / Libraries / libreadline.so_src / main.c
index a12abc5..5937c6b 100644 (file)
@@ -10,6 +10,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
+#include <errno.h>
 
 #define STDIN_FD       0
 #define STDOUT_FD      1
@@ -105,6 +106,7 @@ char *Readline_NonBlock(tReadline *Info)
        }
        
        // Return NULL when command is still being edited
+       errno = EAGAIN;
        return NULL;
 }
 
@@ -116,7 +118,7 @@ char *Readline(tReadline *Info)
        struct ptymode  mode = {.InputMode = 0, .OutputMode = 0};
        _SysIOCtl(STDIN_FD, PTY_IOCTL_SETMODE, &mode);
        
-       while( NULL == (ret = Readline_NonBlock(Info)) );
+       while( NULL == (ret = Readline_NonBlock(Info)) && errno == EAGAIN );
 
        // stty +echo,canon
        mode.InputMode = PTYIMODE_CANON|PTYIMODE_ECHO;
@@ -280,7 +282,7 @@ int Readline_int_ParseCharacter(tReadline *Info, char *Input)
        case '\b':
                if(Info->BufferWritePos <= 0)   break;  // Protect against underflows
                // Write the backsapce
-               _SysWrite(STDOUT_FD, &ch, 1);
+               _SysWrite(STDOUT_FD, "\b \b", 3);
                if(Info->BufferWritePos == Info->BufferUsed)    // Simple case: End of string
                {
                        Info->BufferUsed --;

UCC git Repository :: git.ucc.asn.au