mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-17 23:23:34 +08:00
Use realine instead of fgets in several other places
git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@4357 7fd9a85b-ad96-42d3-883c-3090e2eb8679
This commit is contained in:
@@ -50,6 +50,8 @@
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <apps/readline.h>
|
||||
|
||||
#include <nuttx/usb/usbdev.h>
|
||||
#include <nuttx/usb/usbdev_trace.h>
|
||||
|
||||
@@ -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 */
|
||||
|
||||
if (fgets(g_usbterm.outbuffer, CONFIG_EXAMPLES_USBTERM_BUFLEN, stdin))
|
||||
#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 (ret <= 0)
|
||||
{
|
||||
printf("ERROR: readline failed: %d\n", ret);
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
else
|
||||
{
|
||||
/* Send the line of input via USB */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user