You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2022/03/29 18:36:18 UTC
[incubator-nuttx-apps] branch master updated: nshlib: merge nsh_getdirpath() to nsh_fsutils.c
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git
The following commit(s) were added to refs/heads/master by this push:
new d6a187e nshlib: merge nsh_getdirpath() to nsh_fsutils.c
d6a187e is described below
commit d6a187efed1af13a34a710734eab6387b227f71b
Author: ligd <li...@xiaomi.com>
AuthorDate: Thu Feb 10 15:36:42 2022 +0800
nshlib: merge nsh_getdirpath() to nsh_fsutils.c
Signed-off-by: ligd <li...@xiaomi.com>
---
nshlib/nsh.h | 22 +++++++++++++++++++++-
nshlib/nsh_envcmds.c | 41 -----------------------------------------
nshlib/nsh_fscmds.c | 27 ++-------------------------
nshlib/nsh_fsutils.c | 36 ++++++++++++++++++++++++++++++++++++
4 files changed, 59 insertions(+), 67 deletions(-)
diff --git a/nshlib/nsh.h b/nshlib/nsh.h
index 5efdc89..e2f7ed9 100644
--- a/nshlib/nsh.h
+++ b/nshlib/nsh.h
@@ -490,7 +490,8 @@
*/
#if defined(CONFIG_NSH_DISABLE_LS) && defined(CONFIG_NSH_DISABLE_CP) && \
- defined(CONFIG_NSH_DISABLE_PS) && !defined(CONFIG_NSH_PLATFORM_MOTD)
+ defined(CONFIG_NSH_DISABLE_PS) && !defined(CONFIG_NSH_PLATFORM_MOTD) && \
+ defined(CONFIG_DISABLE_ENVIRON)
# undef NSH_HAVE_IOBUFFER
#endif
@@ -1389,6 +1390,25 @@ FAR char *nsh_trimspaces(FAR char *str);
#endif
/****************************************************************************
+ * Name: nsh_getdirpath
+ *
+ * Description:
+ * Combine dirpath with a file/path, this will genarated a new string,
+ * which need free outside.
+ *
+ * Input Parameters:
+ * dirpath - the dirpath
+ * path - the file/path
+ *
+ * Returned value:
+ * The new string pointer, need free in caller.
+ *
+ ****************************************************************************/
+
+FAR char *nsh_getdirpath(FAR struct nsh_vtbl_s *vtbl,
+ FAR const char *dirpath, FAR const char *path);
+
+/****************************************************************************
* Name: nsh_getvar, nsh_setvar, and nsh_setvar
*
* Description:
diff --git a/nshlib/nsh_envcmds.c b/nshlib/nsh_envcmds.c
index 4b9ee9f..4f9ca87 100644
--- a/nshlib/nsh_envcmds.c
+++ b/nshlib/nsh_envcmds.c
@@ -148,47 +148,6 @@ static inline FAR const char *nsh_getwd(const char *wd)
#endif
/****************************************************************************
- * Name: nsh_getdirpath
- ****************************************************************************/
-
-#ifndef CONFIG_DISABLE_ENVIRON
-static inline char *nsh_getdirpath(FAR struct nsh_vtbl_s *vtbl,
- const char *dirpath, const char *relpath)
-{
- FAR char *alloc;
- int len;
-
- /* Handle the special case where the dirpath is simply "/" */
-
- if (strcmp(dirpath, "/") == 0)
- {
- len = strlen(relpath) + 2;
- alloc = (FAR char *)malloc(len);
- if (alloc)
- {
- sprintf(alloc, "/%s", relpath);
- }
- }
- else
- {
- len = strlen(dirpath) + strlen(relpath) + 2;
- alloc = (FAR char *)malloc(len);
- if (alloc)
- {
- sprintf(alloc, "%s/%s", dirpath, relpath);
- }
- }
-
- if (!alloc)
- {
- nsh_error(vtbl, g_fmtcmdoutofmemory, "nsh_getdirpath");
- }
-
- return alloc;
-}
-#endif
-
-/****************************************************************************
* Name: nsh_dumpvar
****************************************************************************/
diff --git a/nshlib/nsh_fscmds.c b/nshlib/nsh_fscmds.c
index b453517..572753e 100644
--- a/nshlib/nsh_fscmds.c
+++ b/nshlib/nsh_fscmds.c
@@ -85,30 +85,6 @@
****************************************************************************/
/****************************************************************************
- * Name: nsh_getdirpath
- ****************************************************************************/
-
-#if !defined(CONFIG_NSH_DISABLE_LS) || !defined(CONFIG_NSH_DISABLE_CP)
-static char *nsh_getdirpath(FAR struct nsh_vtbl_s *vtbl,
- FAR const char *path, FAR const char *file)
-{
- /* Handle the case where all that is left is '/' */
-
- if (strcmp(path, "/") == 0)
- {
- snprintf(vtbl->iobuffer, IOBUFFERSIZE, "/%s", file);
- }
- else
- {
- snprintf(vtbl->iobuffer, IOBUFFERSIZE, "%s/%s", path, file);
- }
-
- vtbl->iobuffer[PATH_MAX] = '\0';
- return strdup(vtbl->iobuffer);
-}
-#endif
-
-/****************************************************************************
* Name: ls_specialdir
****************************************************************************/
@@ -361,8 +337,9 @@ static int ls_recursive(FAR struct nsh_vtbl_s *vtbl, const char *dirpath,
ret = nsh_foreach_direntry(vtbl, "ls", newpath, ls_recursive,
pvarg);
- free(newpath);
}
+
+ free(newpath);
}
return ret;
diff --git a/nshlib/nsh_fsutils.c b/nshlib/nsh_fsutils.c
index 65dc811..6b3c274 100644
--- a/nshlib/nsh_fsutils.c
+++ b/nshlib/nsh_fsutils.c
@@ -490,3 +490,39 @@ FAR char *nsh_trimspaces(FAR char *str)
return trimmed;
}
#endif
+
+/****************************************************************************
+ * Name: nsh_getdirpath
+ *
+ * Description:
+ * Combine dirpath with a file/path, this will genarated a new string,
+ * which need free outside.
+ *
+ * Input Parameters:
+ * dirpath - the dirpath
+ * path - the file/path
+ *
+ * Returned value:
+ * The new string pointer, need free in caller.
+ *
+ ****************************************************************************/
+
+#ifdef NSH_HAVE_IOBUFFER
+FAR char *nsh_getdirpath(FAR struct nsh_vtbl_s *vtbl,
+ FAR const char *dirpath, FAR const char *path)
+{
+ /* Handle the case where all that is left is '/' */
+
+ if (strcmp(dirpath, "/") == 0)
+ {
+ snprintf(vtbl->iobuffer, IOBUFFERSIZE, "/%s", path);
+ }
+ else
+ {
+ snprintf(vtbl->iobuffer, IOBUFFERSIZE, "%s/%s", dirpath, path);
+ }
+
+ vtbl->iobuffer[PATH_MAX] = '\0';
+ return strdup(vtbl->iobuffer);
+}
+#endif