From 173c985395a0d7e6fd571c9f6d893351f6506dc8 Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Wed, 7 Nov 2018 11:23:07 -0600 Subject: [PATCH] nshlib/nsh_fsutils.c: nsh_catfile() should not append '\n' if the last char in file is already '\n' --- nshlib/nsh_fsutils.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/nshlib/nsh_fsutils.c b/nshlib/nsh_fsutils.c index f6545d64e..c534cdfdd 100644 --- a/nshlib/nsh_fsutils.c +++ b/nshlib/nsh_fsutils.c @@ -76,6 +76,7 @@ int nsh_catfile(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd, FAR const char *filepath) { FAR char *buffer; + char last = 0; int fd; int ret = OK; @@ -131,9 +132,10 @@ int nsh_catfile(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd, { int nbyteswritten = 0; + last = buffer[nbytesread - 1]; while (nbyteswritten < nbytesread) { - ssize_t n = nsh_write(vtbl, buffer, nbytesread); + ssize_t n = nsh_write(vtbl, buffer + nbyteswritten, nbytesread - nbyteswritten); if (n < 0) { int errcode = errno; @@ -177,7 +179,10 @@ int nsh_catfile(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd, * file. */ - nsh_output(vtbl, "\n"); + if (ret == OK && last != '\n') + { + nsh_output(vtbl, "\n"); + } /* Close the input file and return the result */