Skip to content

Commit 4910f8a

Browse files
committed
product-mini/nuttx: Use readline for repl mode
The EOL of NuttX is configurable (CR/LF/CRLF), the implementation of getline in NuttX need CR or LF as line delimiter(CRLF not supported). Then we should use readline for better compatibility. Signed-off-by: Huang Qi <[email protected]>
1 parent 7f4e519 commit 4910f8a

File tree

1 file changed

+13
-4
lines changed
  • product-mini/platforms/nuttx

1 file changed

+13
-4
lines changed

product-mini/platforms/nuttx/main.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#include <stdio.h>
1111
#include <string.h>
1212

13+
#include <system/readline.h>
14+
1315
#include "bh_platform.h"
1416
#include "bh_read_file.h"
1517
#include "wasm_export.h"
@@ -119,13 +121,20 @@ split_string(char *str, int *count)
119121
static void *
120122
app_instance_repl(wasm_module_inst_t module_inst)
121123
{
122-
char *cmd = NULL;
123-
size_t len = 0;
124+
size_t len = 128;
125+
char *cmd = malloc(len);
124126
ssize_t n;
125127

126-
while ((printf("webassembly> "), n = getline(&cmd, &len, stdin)) != -1) {
128+
if (NULL == cmd) {
129+
LOG_ERROR("Wasm repl cmd buffer alloc failed.\n");
130+
return NULL;
131+
}
132+
133+
while (
134+
(printf("webassembly> "), fflush(stdout), n = std_readline(cmd, len))
135+
!= -1) {
127136
bh_assert(n > 0);
128-
if (cmd[n - 1] == '\n') {
137+
if ((cmd[n - 1] == '\n') || (cmd[n - 1] == '\r')) {
129138
if (n == 1)
130139
continue;
131140
else

0 commit comments

Comments
 (0)