From 4041ad545516f94eb7de87c8709fbb0f226f291b Mon Sep 17 00:00:00 2001 From: patacongo Date: Mon, 11 Jun 2012 23:47:31 +0000 Subject: Add NSH mv command git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4830 42af7a65-404d-4744-a932-0658087f49c3 --- apps/nshlib/nsh_fscmds.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'apps/nshlib/nsh_fscmds.c') diff --git a/apps/nshlib/nsh_fscmds.c b/apps/nshlib/nsh_fscmds.c index c67ccf3b2..b3b4ae770 100644 --- a/apps/nshlib/nsh_fscmds.c +++ b/apps/nshlib/nsh_fscmds.c @@ -1212,6 +1212,50 @@ int cmd_mount(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) #endif #endif +/**************************************************************************** + * Name: cmd_mv + ****************************************************************************/ + +#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_FS_WRITABLE) +#ifndef CONFIG_NSH_DISABLE_MV +int cmd_mv(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) +{ + char *oldpath; + char *newpath; + int ret; + + /* Get the full path to the old and new file paths */ + + oldpath = nsh_getfullpath(vtbl, argv[1]); + if (!oldpath) + { + return ERROR; + } + + newpath = nsh_getfullpath(vtbl, argv[2]); + if (!newpath) + { + nsh_freefullpath(newpath); + return ERROR; + } + + /* Perform the mount */ + + ret = rename(oldpath, newpath); + if (ret < 0) + { + nsh_output(vtbl, g_fmtcmdfailed, argv[0], "rename", NSH_ERRNO); + } + + /* Free the file paths */ + + nsh_freefullpath(oldpath); + nsh_freefullpath(newpath); + return ret; +} +#endif +#endif + /**************************************************************************** * Name: cmd_nfsmount ****************************************************************************/ -- cgit v1.2.3