nshlib: merge nsh_getdirpath() to nsh_fsutils.c
Signed-off-by: ligd <liguiding1@xiaomi.com>
This commit is contained in:
parent
ec15dc0344
commit
d6a187efed
22
nshlib/nsh.h
22
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
|
||||
|
||||
@ -1388,6 +1389,25 @@ void nsh_trimdir(FAR char *dirpath);
|
||||
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
|
||||
*
|
||||
|
@ -147,47 +147,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
|
||||
****************************************************************************/
|
||||
|
@ -84,30 +84,6 @@
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* 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;
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user