summaryrefslogtreecommitdiff
path: root/apps/netutils/ftpc/ftpc_pwd.c
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2011-06-02 23:45:31 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2011-06-02 23:45:31 +0000
commit80d5b281209708972a1e484f10f9b1cf74868ea4 (patch)
tree055ca499f7321151291d83afc6a5585c0bdde1ae /apps/netutils/ftpc/ftpc_pwd.c
parent944bf89644559cd2ae021122451ff5d0a740cb85 (diff)
downloadnuttx-80d5b281209708972a1e484f10f9b1cf74868ea4.tar.gz
nuttx-80d5b281209708972a1e484f10f9b1cf74868ea4.tar.bz2
nuttx-80d5b281209708972a1e484f10f9b1cf74868ea4.zip
More FTP client debug fixes
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3662 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'apps/netutils/ftpc/ftpc_pwd.c')
-rw-r--r--apps/netutils/ftpc/ftpc_pwd.c34
1 files changed, 29 insertions, 5 deletions
diff --git a/apps/netutils/ftpc/ftpc_pwd.c b/apps/netutils/ftpc/ftpc_pwd.c
index f6bde0e13..809002c9b 100644
--- a/apps/netutils/ftpc/ftpc_pwd.c
+++ b/apps/netutils/ftpc/ftpc_pwd.c
@@ -37,7 +37,7 @@
* Included Files
****************************************************************************/
-#include <nuttx/config.h>
+#include "ftpc_config.h"
#include <stdlib.h>
#include <string.h>
@@ -86,26 +86,50 @@ FAR char *ftpc_pwd(SESSION handle)
FAR char *end;
FAR char *pwd;
FAR char *ptr;
+ int len;
int ret;
+ /* Send the PWD command */
+
ret = ftpc_cmd(session, "PWD");
+
+ /* Response is like: 257 "/home/gnutt" (from vsftpd).
+ *
+ * Extract the quoated path name into allocated memory.
+ */
+
start = strchr(session->reply, '\"');
if (!start)
{
ndbg("Opening quote not found\n");
return NULL;
}
-
start++;
+
end = strchr(start, '\"');
if (!end)
{
- ndbg("Clsoing quote not found\n");
+ ndbg("Closing quote not found\n");
+ return NULL;
+ }
+
+ /* Allocate memory for the path name */
+
+ len = end - start;
+ pwd = (char *)malloc(len + 1);
+ if (!pwd)
+ {
+ ndbg("Failed to allocate string\n");
return NULL;
}
+
+ /* Copy the string into the allocated memory */
+
+ memcpy(pwd, start, len);
+ pwd[len] = '\0';
+
+ /* Remove any trailing slashes that the server may have added */
- pwd = (char *)malloc(end-start+1);
- strncpy(pwd, start, end-start);
ftpc_stripslash(pwd);
/* Change DOS style directory separator ('\') to UNIX style ('/') */