From 37259910ba73b71e4c32e5913e4d44c245c4502d Mon Sep 17 00:00:00 2001 From: patacongo Date: Wed, 1 Feb 2012 19:47:12 +0000 Subject: Use realine instead of fgets in several other places git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4357 42af7a65-404d-4744-a932-0658087f49c3 --- apps/examples/usbterm/usbterm_main.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'apps/examples/usbterm') diff --git a/apps/examples/usbterm/usbterm_main.c b/apps/examples/usbterm/usbterm_main.c index d51101dd7..066c6f548 100644 --- a/apps/examples/usbterm/usbterm_main.c +++ b/apps/examples/usbterm/usbterm_main.c @@ -50,6 +50,8 @@ #include #include +#include + #include #include @@ -297,9 +299,32 @@ int MAIN_NAME(int argc, char *argv[]) fputs("usbterm> ", stdout); fflush(stdout); - /* Get the next line of input from stdin */ + /* Get the next line of input */ + +#ifdef CONFIG_EXAMPLES_USBTERM_FGETS + /* fgets returns NULL on end-of-file or any I/O error */ + + if (fgets(g_usbterm.outbuffer, CONFIG_EXAMPLES_USBTERM_BUFLEN, stdin) == NULL) + { + printf("ERROR: fgets failed: %d\n", errno); + return 1; + } +#else + ret = readline(g_usbterm.outbuffer, CONFIG_EXAMPLES_USBTERM_BUFLEN, stdin, stdout); + + /* Readline normally returns the number of characters read, + * but will return 0 on end of file or a negative value + * if an error occurs. Either will cause the session to + * terminate. + */ - if (fgets(g_usbterm.outbuffer, CONFIG_EXAMPLES_USBTERM_BUFLEN, stdin)) + if (ret <= 0) + { + printf("ERROR: readline failed: %d\n", ret); + return 1; + } +#endif + else { /* Send the line of input via USB */ -- cgit v1.2.3