summaryrefslogtreecommitdiff
path: root/nuttx/examples/nsh/nsh_fscmds.c
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2008-08-22 00:07:57 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2008-08-22 00:07:57 +0000
commitab92a9dd0a6a84517ec966e5c79e4e692970ba16 (patch)
tree540775f4354c71329d4935d01801dfca5c047b01 /nuttx/examples/nsh/nsh_fscmds.c
parentf77ac6a9d33041e23ff3c82c26b1c3cff3b3e513 (diff)
downloadpx4-nuttx-ab92a9dd0a6a84517ec966e5c79e4e692970ba16.tar.gz
px4-nuttx-ab92a9dd0a6a84517ec966e5c79e4e692970ba16.tar.bz2
px4-nuttx-ab92a9dd0a6a84517ec966e5c79e4e692970ba16.zip
cat accepts multiple files
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@836 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/examples/nsh/nsh_fscmds.c')
-rw-r--r--nuttx/examples/nsh/nsh_fscmds.c96
1 files changed, 53 insertions, 43 deletions
diff --git a/nuttx/examples/nsh/nsh_fscmds.c b/nuttx/examples/nsh/nsh_fscmds.c
index 75bbfc8e9..144cea9a4 100644
--- a/nuttx/examples/nsh/nsh_fscmds.c
+++ b/nuttx/examples/nsh/nsh_fscmds.c
@@ -375,72 +375,82 @@ static int ls_recursive(FAR struct nsh_vtbl_s *vtbl, const char *dirpath, struct
int cmd_cat(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
{
char buffer[IOBUFFERSIZE];
- int ret = ERROR;
-
- /* Open the file for reading */
-
- int fd = open(argv[1], O_RDONLY);
- if (fd < 0)
- {
- nsh_output(vtbl, g_fmtcmdfailed, argv[0], "open", NSH_ERRNO);
- return ERROR;
- }
+ int fd;
+ int i;
+ int ret = OK;
- /* And just dump it byte for byte into stdout */
+ /* Loop for each file name on the command line */
- for (;;)
+ for (i = 1; i < argc && ret == OK; i++)
{
- int nbytesread = read(fd, buffer, IOBUFFERSIZE);
+ /* Open the file for reading */
- /* Check for read errors */
-
- if (nbytesread < 0)
+ fd = open(argv[1], O_RDONLY);
+ if (fd < 0)
{
- /* EINTR is not an error */
-
- if (errno != EINTR)
- {
- nsh_output(vtbl, g_fmtcmdfailed, argv[0], "read", NSH_ERRNO);
- break;
- }
+ nsh_output(vtbl, g_fmtcmdfailed, argv[0], "open", NSH_ERRNO);
+ ret = ERROR;
}
-
- /* Check for data successfully read */
-
- else if (nbytesread > 0)
+ else
{
- int nbyteswritten = 0;
+ /* And just dump it byte for byte into stdout */
- while (nbyteswritten < nbytesread)
+ for (;;)
{
- int n = write(1, buffer, nbytesread);
- if (n < 0)
+ int nbytesread = read(fd, buffer, IOBUFFERSIZE);
+
+ /* Check for read errors */
+
+ if (nbytesread < 0)
{
- /* EINTR is not an error */
+ /* EINTR is not an error */
if (errno != EINTR)
{
- nsh_output(vtbl, g_fmtcmdfailed, argv[0], "write", NSH_ERRNO);
+ nsh_output(vtbl, g_fmtcmdfailed, argv[0], "read", NSH_ERRNO);
+ ret = ERROR;
break;
}
}
+
+ /* Check for data successfully read */
+
+ else if (nbytesread > 0)
+ {
+ int nbyteswritten = 0;
+
+ while (nbyteswritten < nbytesread)
+ {
+ int n = write(1, buffer, nbytesread);
+ if (n < 0)
+ {
+ /* EINTR is not an error */
+
+ if (errno != EINTR)
+ {
+ nsh_output(vtbl, g_fmtcmdfailed, argv[0], "write", NSH_ERRNO);
+ ret = ERROR;
+ break;
+ }
+ }
+ else
+ {
+ nbyteswritten += n;
+ }
+ }
+ }
+
+ /* Otherwise, it is the end of file */
+
else
{
- nbyteswritten += n;
+ break;
}
}
- }
-
- /* Otherwise, it is the end of file */
- else
- {
- ret = OK;
- break;
+ (void)close(fd);
}
}
-
- (void)close(fd);
return ret;
}
#endif