mirror of
https://github.com/apache/nuttx-apps.git
synced 2025-10-19 11:23:07 +08:00
nshlib/cmd_memdump: support new command: memdump
Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
This commit is contained in:
@@ -286,6 +286,65 @@ int nsh_readfile(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd,
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nsh_writefile
|
||||
*
|
||||
* Description:
|
||||
* Dump the contents of a file to the current NSH terminal.
|
||||
*
|
||||
* Input Paratemets:
|
||||
* vtbl - session vtbl
|
||||
* cmd - NSH command name to use in error reporting
|
||||
* buffer - The pointer of writting buffer
|
||||
* len - The length of writting buffer
|
||||
* filepath - The full path to the file to be dumped
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) on success; -1 (ERROR) on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef NSH_HAVE_WRITEFILE
|
||||
int nsh_writefile(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd,
|
||||
FAR const char *buffer, size_t len,
|
||||
FAR const char *filepath)
|
||||
{
|
||||
int fd;
|
||||
int ret;
|
||||
|
||||
/* Open the file for reading */
|
||||
|
||||
fd = open(filepath, O_WRONLY);
|
||||
if (fd < 0)
|
||||
{
|
||||
#if defined(CONFIG_NSH_PROC_MOUNTPOINT)
|
||||
if (strncmp(filepath, CONFIG_NSH_PROC_MOUNTPOINT,
|
||||
strlen(CONFIG_NSH_PROC_MOUNTPOINT)) == 0)
|
||||
{
|
||||
nsh_error(vtbl,
|
||||
"nsh: %s: Could not open %s (is procfs mounted?): %d\n",
|
||||
cmd, filepath, NSH_ERRNO);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
nsh_error(vtbl, g_fmtcmdfailed, cmd, "open", NSH_ERRNO);
|
||||
}
|
||||
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
ret = write(fd, buffer, len);
|
||||
if (ret < 0)
|
||||
{
|
||||
nsh_error(vtbl, g_fmtcmdfailed, cmd, "write", NSH_ERRNO);
|
||||
}
|
||||
|
||||
close(fd);
|
||||
return ret > 0 ? OK : ERROR;
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nsh_foreach_direntry
|
||||
*
|
||||
|
Reference in New Issue
Block a user