summaryrefslogtreecommitdiff
path: root/apps/examples/ftpc
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2012-02-01 19:47:12 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2012-02-01 19:47:12 +0000
commit37259910ba73b71e4c32e5913e4d44c245c4502d (patch)
tree9b5b0a7b3d6180141c3f9d959b6c04647e4a6810 /apps/examples/ftpc
parent6d35541209058b86bda7b34e47fa28c8c959d365 (diff)
downloadnuttx-37259910ba73b71e4c32e5913e4d44c245c4502d.tar.gz
nuttx-37259910ba73b71e4c32e5913e4d44c245c4502d.tar.bz2
nuttx-37259910ba73b71e4c32e5913e4d44c245c4502d.zip
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
Diffstat (limited to 'apps/examples/ftpc')
-rw-r--r--apps/examples/ftpc/ftpc_main.c37
1 files changed, 33 insertions, 4 deletions
diff --git a/apps/examples/ftpc/ftpc_main.c b/apps/examples/ftpc/ftpc_main.c
index 7a1cb50f7..9093b0c10 100644
--- a/apps/examples/ftpc/ftpc_main.c
+++ b/apps/examples/ftpc/ftpc_main.c
@@ -1,8 +1,8 @@
/****************************************************************************
* examples/ftpc/ftpc_main.c
*
- * Copyright (C) 2011 Gregory Nutt. All rights reserved.
- * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
+ * Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -41,10 +41,13 @@
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
+#include <errno.h>
#include <arpa/inet.h>
#include <apps/ftpc.h>
+#include <apps/readline.h>
+
#include "ftpc.h"
/****************************************************************************
@@ -357,6 +360,9 @@ int ftpc_main(int argc, char **argv, char **envp)
struct ftpc_connect_s connect = {{0}, 0};
SESSION handle;
FAR char *ptr;
+#ifndef CONFIG_EXAMPLES_FTPC_FGETS
+ int ret;
+#endif
if (argc != 2)
{
@@ -413,9 +419,32 @@ int ftpc_main(int argc, char **argv, char **envp)
/* Get the next line of input */
- if (fgets(g_line, CONFIG_FTPC_LINELEN, stdin))
+#ifdef CONFIG_EXAMPLES_FTPC_FGETS
+ /* fgets returns NULL on end-of-file or any I/O error */
+
+ if (fgets(g_line, CONFIG_FTPC_LINELEN, stdin) == NULL)
+ {
+ printf("ERROR: fgets failed: %d\n", errno);
+ return 1;
+ }
+#else
+ ret = readline(g_line, CONFIG_FTPC_LINELEN, 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
{
- /* Parse process the command */
+ /* Parse and process the command */
(void)ftpc_parse(handle, g_line);
FFLUSH();