summaryrefslogtreecommitdiff
path: root/apps/nshlib/nsh_console.c
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2013-10-01 11:52:35 -0600
committerGregory Nutt <gnutt@nuttx.org>2013-10-01 11:52:35 -0600
commitedb29aa64e325bc41f0feb8a8a784bdad483a0a6 (patch)
treedb4afdc6e389e6a5ee4acce476f230c4672f2698 /apps/nshlib/nsh_console.c
parent6d00b3a3f845a49b3755a5fd02db194b60f3295b (diff)
downloadnuttx-edb29aa64e325bc41f0feb8a8a784bdad483a0a6.tar.gz
nuttx-edb29aa64e325bc41f0feb8a8a784bdad483a0a6.tar.bz2
nuttx-edb29aa64e325bc41f0feb8a8a784bdad483a0a6.zip
More improvements to the minimal NSH when there is no file system and when print fieldwidths are suppressed
Diffstat (limited to 'apps/nshlib/nsh_console.c')
-rw-r--r--apps/nshlib/nsh_console.c27
1 files changed, 23 insertions, 4 deletions
diff --git a/apps/nshlib/nsh_console.c b/apps/nshlib/nsh_console.c
index 410abc19d..41e992678 100644
--- a/apps/nshlib/nsh_console.c
+++ b/apps/nshlib/nsh_console.c
@@ -198,6 +198,8 @@ static ssize_t nsh_consolewrite(FAR struct nsh_vtbl_s *vtbl, FAR const void *buf
}
return ret;
#else
+ /* REVISIT: buffer may not be NUL-terminated */
+
printf("%s", buffer);
return nbytes;
#endif
@@ -234,13 +236,30 @@ static int nsh_consoleoutput(FAR struct nsh_vtbl_s *vtbl, const char *fmt, ...)
return ret;
#else
- char dest[64 * 16];
+ va_list ap;
+ char *str;
+ int ret;
+
+ /* Use avsprintf() to allocate a buffer and fill it with the formatted
+ * data
+ */
va_start(ap, fmt);
- vsprintf(dest, fmt, ap);
- va_end(ap);
+ str = NULL;
+ (void)avsprintf(&str, fmt, ap);
+
+ /* Was a string allocated? */
- return printf(dest);
+ if (str)
+ {
+ /* Yes.. Print then free the allocated string */
+
+ printf("%s", str);
+ free(str);
+ }
+
+ va_end(ap);
+ return 0;
#endif
}