nshlib/nsh_fsutils.c: nsh_catfile() should not append '\n' if the last char in file is already '\n'
This commit is contained in:
parent
19dc7cd3b3
commit
173c985395
@ -76,6 +76,7 @@ int nsh_catfile(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd,
|
|||||||
FAR const char *filepath)
|
FAR const char *filepath)
|
||||||
{
|
{
|
||||||
FAR char *buffer;
|
FAR char *buffer;
|
||||||
|
char last = 0;
|
||||||
int fd;
|
int fd;
|
||||||
int ret = OK;
|
int ret = OK;
|
||||||
|
|
||||||
@ -131,9 +132,10 @@ int nsh_catfile(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd,
|
|||||||
{
|
{
|
||||||
int nbyteswritten = 0;
|
int nbyteswritten = 0;
|
||||||
|
|
||||||
|
last = buffer[nbytesread - 1];
|
||||||
while (nbyteswritten < nbytesread)
|
while (nbyteswritten < nbytesread)
|
||||||
{
|
{
|
||||||
ssize_t n = nsh_write(vtbl, buffer, nbytesread);
|
ssize_t n = nsh_write(vtbl, buffer + nbyteswritten, nbytesread - nbyteswritten);
|
||||||
if (n < 0)
|
if (n < 0)
|
||||||
{
|
{
|
||||||
int errcode = errno;
|
int errcode = errno;
|
||||||
@ -177,7 +179,10 @@ int nsh_catfile(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd,
|
|||||||
* file.
|
* file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
nsh_output(vtbl, "\n");
|
if (ret == OK && last != '\n')
|
||||||
|
{
|
||||||
|
nsh_output(vtbl, "\n");
|
||||||
|
}
|
||||||
|
|
||||||
/* Close the input file and return the result */
|
/* Close the input file and return the result */
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user