mirror of
https://github.com/apache/nuttx-apps.git
synced 2025-10-17 15:32:21 +08:00
Several patches from Petteri Aimonen (mostly NxWidgets)
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5324 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
@@ -46,6 +46,10 @@
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#if CONFIG_NFILE_DESCRIPTORS > 0
|
||||
# include <fcntl.h>
|
||||
#endif
|
||||
|
||||
#include "nsh.h"
|
||||
#include "nsh_console.h"
|
||||
|
||||
@@ -327,7 +331,7 @@ void nsh_dumpbuffer(FAR struct nsh_vtbl_s *vtbl, const char *msg,
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: cmd_xd
|
||||
* Name: cmd_xd, hex dump of memory
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_NSH_DISABLE_XD
|
||||
@@ -353,3 +357,57 @@ int cmd_xd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
return OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: cmd_hexdump, hex dump of files
|
||||
****************************************************************************/
|
||||
|
||||
#if CONFIG_NFILE_DESCRIPTORS > 0
|
||||
#ifndef CONFIG_NSH_DISABLE_HEXDUMP
|
||||
int cmd_hexdump(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
{
|
||||
uint8_t buffer[IOBUFFERSIZE];
|
||||
int fd;
|
||||
int ret = OK;
|
||||
char msg[32];
|
||||
|
||||
/* Open the file for reading */
|
||||
|
||||
fd = open(argv[1], O_RDONLY);
|
||||
if (fd < 0)
|
||||
{
|
||||
nsh_output(vtbl, g_fmtcmdfailed, "hexdump", "open", NSH_ERRNO);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
int position = 0;
|
||||
for (;;)
|
||||
{
|
||||
int nbytesread = read(fd, buffer, IOBUFFERSIZE);
|
||||
|
||||
/* Check for read errors */
|
||||
|
||||
if (nbytesread < 0)
|
||||
{
|
||||
int errval = errno;
|
||||
nsh_output(vtbl, g_fmtcmdfailed, "hexdump", "read", NSH_ERRNO_OF(errval));
|
||||
ret = ERROR;
|
||||
break;
|
||||
}
|
||||
else if (nbytesread > 0)
|
||||
{
|
||||
snprintf(msg, sizeof(msg), "%s at %08x", argv[1], position);
|
||||
nsh_dumpbuffer(vtbl, msg, buffer, nbytesread);
|
||||
position += nbytesread;
|
||||
}
|
||||
else
|
||||
{
|
||||
break; // EOF
|
||||
}
|
||||
}
|
||||
|
||||
(void)close(fd);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user