summaryrefslogtreecommitdiff
path: root/apps/netutils
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2011-06-05 16:46:27 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2011-06-05 16:46:27 +0000
commit672c0505c6c10c227c9315ed4f94746462392ea5 (patch)
treef30aa3ac2eceee1f822ff4b7e5b2851ac8fea785 /apps/netutils
parentd6e0fecec1f8b8bfa14784fa2a33f5f4da66148e (diff)
downloadnuttx-672c0505c6c10c227c9315ed4f94746462392ea5.tar.gz
nuttx-672c0505c6c10c227c9315ed4f94746462392ea5.tar.bz2
nuttx-672c0505c6c10c227c9315ed4f94746462392ea5.zip
Fix more FTP bugs
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3671 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'apps/netutils')
-rw-r--r--apps/netutils/ftpc/ftpc_getfile.c30
-rw-r--r--apps/netutils/ftpc/ftpc_putfile.c2
-rw-r--r--apps/netutils/ftpc/ftpc_transfer.c1
3 files changed, 21 insertions, 12 deletions
diff --git a/apps/netutils/ftpc/ftpc_getfile.c b/apps/netutils/ftpc/ftpc_getfile.c
index 366351636..6077b7580 100644
--- a/apps/netutils/ftpc/ftpc_getfile.c
+++ b/apps/netutils/ftpc/ftpc_getfile.c
@@ -181,7 +181,6 @@ static int ftpc_recvbinary(FAR struct ftpc_session_s *session,
ssize_t nread;
ssize_t nwritten;
int err;
- int ret = OK;
/* Allocate an I/O buffer */
@@ -199,16 +198,20 @@ static int ftpc_recvbinary(FAR struct ftpc_session_s *session,
nread = fread(buf, sizeof(char), CONFIG_FTP_BUFSIZE, rinstream);
if (nread <= 0)
{
- /* nread == 0 means end of file */
+ /* nread < 0 is an error */
if (nread < 0)
{
/* errno should already be set by fread */
(void)ftpc_xfrabort(session, rinstream);
- ret = ERROR;
+ goto errout_with_buf;
}
- break;
+
+ /* nread == 0 means end of file. Return success */
+
+ free(buf);
+ return OK;
}
/* Write the data to the file */
@@ -217,19 +220,24 @@ static int ftpc_recvbinary(FAR struct ftpc_session_s *session,
if (nwritten != nread)
{
(void)ftpc_xfrabort(session, loutstream);
- ret = ERROR;
- break;
+
+ /* If nwritten < 0 errno should already be set by fwrite.
+ * What would a short write mean?
+ */
+
+ goto errout_with_buf;
}
- session->size += nread;
+ /* Increment the size of the file written */
+
+ session->size += nwritten;
}
+errout_with_buf: /* Buffer allocated, errno already set */
free(buf);
- return ret;
+ return ERROR;
-errout_with_buf:
- free(buf);
-errout_with_err:
+errout_with_err: /* Buffer not allocated, errno needs to be set */
set_errno(err);
return ERROR;
}
diff --git a/apps/netutils/ftpc/ftpc_putfile.c b/apps/netutils/ftpc/ftpc_putfile.c
index bc20853d7..4a15d7410 100644
--- a/apps/netutils/ftpc/ftpc_putfile.c
+++ b/apps/netutils/ftpc/ftpc_putfile.c
@@ -422,7 +422,7 @@ int ftp_putfile(SESSION handle, const char *lname, const char *rname,
/* Open the local file for reading */
finstream = fopen(abslpath, "r");
- if (!finstream == 0)
+ if (!finstream)
{
ndbg("fopen() failed: %d\n", errno);
goto errout_with_abspath;
diff --git a/apps/netutils/ftpc/ftpc_transfer.c b/apps/netutils/ftpc/ftpc_transfer.c
index f808e67fb..7bbe30f2c 100644
--- a/apps/netutils/ftpc/ftpc_transfer.c
+++ b/apps/netutils/ftpc/ftpc_transfer.c
@@ -44,6 +44,7 @@
#include <unistd.h>
#include <string.h>
#include <signal.h>
+#include <poll.h>
#include <ctype.h>
#include <errno.h>
#include <assert.h>