When an async operation dies, orphan its children.
[people/xl0/gpxe.git] / src / hci / readline.c
index 36ba429..420df64 100644 (file)
@@ -17,8 +17,9 @@
  */
 
 #include <string.h>
-#include <malloc.h>
+#include <stdlib.h>
 #include <console.h>
+#include <gpxe/keys.h>
 #include <gpxe/editstring.h>
 #include <readline/readline.h>
 
@@ -79,35 +80,35 @@ static void sync_console ( struct edit_string *string ) {
  */
 char * readline ( const char *prompt ) {
        char buf[READLINE_MAX];
-       struct edit_string string = {
-               .buf = buf,
-               .len = sizeof ( buf ),
-               .cursor = 0,
-       };
+       struct edit_string string;
        int key;
-       char *line = NULL;
+       char *line;
 
        if ( prompt )
                printf ( "%s", prompt );
 
+       memset ( &string, 0, sizeof ( string ) );
+       string.buf = buf;
+       string.len = sizeof ( buf );
        buf[0] = '\0';
+
        while ( 1 ) {
-               key = edit_string ( &string, getchar() );
+               key = edit_string ( &string, getkey() );
                sync_console ( &string );
                switch ( key ) {
-               case 0x0d: /* Carriage return */
-               case 0x0a: /* Line feed */
+               case CR:
+               case LF:
+                       putchar ( '\n' );
                        line = strdup ( buf );
-                       goto out;
-               case 0x03: /* Ctrl-C */
-                       goto out;
+                       if ( ! line )
+                               printf ( "Out of memory\n" );
+                       return line;
+               case CTRL_C:
+                       putchar ( '\n' );
+                       return NULL;
                default:
                        /* Do nothing */
                        break;
                }
        }
-
- out:
-       putchar ( '\n' );
-       return line;
 }