summaryrefslogtreecommitdiff
path: root/apps/nshlib/nsh_mntcmds.c
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2012-09-08 13:56:21 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2012-09-08 13:56:21 +0000
commitb4420923cb149a5a8164bb06794e12b88203d97c (patch)
tree0622029fef5305661e1a27dbc8a8d6b7db1cf79a /apps/nshlib/nsh_mntcmds.c
parenta386a5f0c85cd610b0d8a952c2a28f4038094fa4 (diff)
downloadnuttx-b4420923cb149a5a8164bb06794e12b88203d97c.tar.gz
nuttx-b4420923cb149a5a8164bb06794e12b88203d97c.tar.bz2
nuttx-b4420923cb149a5a8164bb06794e12b88203d97c.zip
Shenzhou board is first to use ONLY Kconfig for configuration
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5114 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'apps/nshlib/nsh_mntcmds.c')
-rw-r--r--apps/nshlib/nsh_mntcmds.c30
1 files changed, 24 insertions, 6 deletions
diff --git a/apps/nshlib/nsh_mntcmds.c b/apps/nshlib/nsh_mntcmds.c
index b5935bdea..027046c77 100644
--- a/apps/nshlib/nsh_mntcmds.c
+++ b/apps/nshlib/nsh_mntcmds.c
@@ -195,9 +195,9 @@ int cmd_df(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
defined(CONFIG_FS_READABLE) && !defined(CONFIG_NSH_DISABLE_MOUNT)
int cmd_mount(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
{
- char *source;
- char *target;
- char *filesystem = 0;
+ FAR char *source;
+ FAR char *target;
+ FAR char *filesystem = NULL;
bool badarg = false;
int ret;
@@ -208,7 +208,11 @@ int cmd_mount(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
return mount_show(vtbl, argv[0]);
}
- /* Get the mount options */
+ /* Get the mount options. NOTE: getopt() is not thread safe nor re-entrant.
+ * To keep its state proper for the next usage, it is necessary to parse to
+ * the end of the line even if an error occurs. If an error occurs, this
+ * logic just sets 'badarg' and continues.
+ */
int option;
while ((option = getopt(argc, argv, ":t:")) != ERROR)
@@ -232,14 +236,18 @@ int cmd_mount(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
}
}
- /* If a bad argument was encountered, then return without processing the command */
+ /* If a bad argument was encountered, then return without processing the
+ * command.
+ */
if (badarg)
{
return ERROR;
}
- /* There are two required arguments after the options */
+ /* There are two required arguments after the options: the source and target
+ * paths.
+ */
if (optind + 2 < argc)
{
@@ -252,6 +260,16 @@ int cmd_mount(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
return ERROR;
}
+ /* While the above parsing for the -t argument looks nice, the -t argument
+ * not really optional.
+ */
+
+ if (!filesystem)
+ {
+ nsh_output(vtbl, g_fmtargrequired, argv[0]);
+ return ERROR;
+ }
+
/* The source and target paths might be relative to the current
* working directory.
*/