summaryrefslogtreecommitdiff
path: root/nuttx/configs/16z/tools/zneo-zdsii-5_0_1-variadic-func-fix.patch
blob: b22efeb86dce9d227c3ba679f2df61a7b2eac7c7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
diff --git a/apps/nshlib/nsh_console.c b/apps/nshlib/nsh_console.c
index ba7dbe7..45e4ab1 100644
--- a/apps/nshlib/nsh_console.c
+++ b/apps/nshlib/nsh_console.c
@@ -46,6 +46,7 @@
 #include <unistd.h>
 #include <fcntl.h>
 #include <string.h>
+#include <stdarg.h>
 #include <assert.h>
 #include <errno.h>
 #include <debug.h>
@@ -79,8 +80,13 @@ static FAR struct nsh_vtbl_s *nsh_consoleclone(FAR struct nsh_vtbl_s *vtbl);
 static void nsh_consolerelease(FAR struct nsh_vtbl_s *vtbl);
 static ssize_t nsh_consolewrite(FAR struct nsh_vtbl_s *vtbl,
   FAR const void *buffer, size_t nbytes);
+#if 0
 static int nsh_consoleoutput(FAR struct nsh_vtbl_s *vtbl,
   FAR const char *fmt, ...);
+#else
+static int nsh_consolevoutput(FAR struct nsh_vtbl_s *vtbl,
+  FAR const char *fmt, va_list ap);
+#endif
 static FAR char *nsh_consolelinebuffer(FAR struct nsh_vtbl_s *vtbl);
 
 #if CONFIG_NFILE_DESCRIPTORS > 0
@@ -213,6 +219,7 @@ static ssize_t nsh_consolewrite(FAR struct nsh_vtbl_s *vtbl, FAR const void *buf
  *
  ****************************************************************************/
 
+#if 0
 static int nsh_consoleoutput(FAR struct nsh_vtbl_s *vtbl,
                              FAR const char *fmt, ...)
 {
@@ -263,6 +270,51 @@ static int nsh_consoleoutput(FAR struct nsh_vtbl_s *vtbl,
 #endif
 }
 
+#else
+static int nsh_consolevoutput(FAR struct nsh_vtbl_s *vtbl, FAR const char *fmt, va_list ap)
+{
+#if CONFIG_NFILE_DESCRIPTORS > 0
+  FAR struct console_stdio_s *pstate = (FAR struct console_stdio_s *)vtbl;
+  int ret;
+
+  /* The stream is open in a lazy fashion.  This is done because the file
+   * descriptor may be opened on a different task than the stream.  The
+   * actual open will then occur with the first output from the new task.
+   */
+
+  if (nsh_openifnotopen(pstate) != 0)
+   {
+     return ERROR;
+   }
+
+  ret = vfprintf(pstate->cn_outstream, fmt, ap);
+
+  return ret;
+#else
+  char *str;
+
+  /* Use avsprintf() to allocate a buffer and fill it with the formatted
+   * data
+   */
+
+  str = NULL;
+  (void)avsprintf(&str, fmt, ap);
+
+  /* Was a string allocated? */
+
+  if (str)
+    {
+      /* Yes.. Print then free the allocated string */
+
+      printf("%s", str);
+      free(str);
+    }
+
+  return 0;
+#endif
+}
+#endif
+
 /****************************************************************************
  * Name: nsh_consolelinebuffer
  *
@@ -452,7 +504,11 @@ FAR struct console_stdio_s *nsh_newconsole(void)
       pstate->cn_vtbl.release    = nsh_consolerelease;
 #endif
       pstate->cn_vtbl.write      = nsh_consolewrite;
+#if 0
       pstate->cn_vtbl.output     = nsh_consoleoutput;
+#else
+      pstate->cn_vtbl.voutput    = nsh_consolevoutput;
+#endif
       pstate->cn_vtbl.linebuffer = nsh_consolelinebuffer;
       pstate->cn_vtbl.exit       = nsh_consoleexit;
 
@@ -489,3 +545,15 @@ FAR struct console_stdio_s *nsh_newconsole(void)
     }
   return pstate;
 }
+
+int nsh_output(FAR struct nsh_vtbl_s *vtbl, FAR const char *fmt, ...)
+{
+  va_list ap;
+  int ret;
+
+  va_start(ap, fmt);
+  ret = vtbl->voutput(vtbl, fmt, ap);
+  va_end(ap);
+
+  return ret;
+}
diff --git a/apps/nshlib/nsh_console.h b/apps/nshlib/nsh_console.h
index c78362f..207f9b9 100644
--- a/apps/nshlib/nsh_console.h
+++ b/apps/nshlib/nsh_console.h
@@ -47,6 +47,7 @@
 #include <stdio.h>
 #include <stdint.h>
 #include <stdbool.h>
+#include <stdarg.h>
 #include <errno.h>
 
 /****************************************************************************
@@ -62,11 +63,13 @@
 #define nsh_undirect(v,s)      (v)->undirect(v,s)
 #define nsh_exit(v,s)          (v)->exit(v,s)
 
+#if 0
 #ifdef CONFIG_CPP_HAVE_VARARGS
 # define nsh_output(v, fmt...) (v)->output(v, ##fmt)
 #else
 # define nsh_output            vtbl->output
 #endif
+#endif
 
 /* Size of info to be saved in call to nsh_redirect */
 
@@ -107,7 +110,11 @@ struct nsh_vtbl_s
   void (*release)(FAR struct nsh_vtbl_s *vtbl);
 #endif
   ssize_t (*write)(FAR struct nsh_vtbl_s *vtbl, FAR const void *buffer, size_t nbytes);
+#if 0
   int (*output)(FAR struct nsh_vtbl_s *vtbl, FAR const char *fmt, ...);
+#else
+  int (*voutput)(FAR struct nsh_vtbl_s *vtbl, FAR const char *fmt, va_list ap);
+#endif
   FAR char *(*linebuffer)(FAR struct nsh_vtbl_s *vtbl);
 #if CONFIG_NFILE_DESCRIPTORS > 0
   void (*redirect)(FAR struct nsh_vtbl_s *vtbl, int fd, FAR uint8_t *save);
@@ -159,5 +166,6 @@ struct console_stdio_s
 /* Defined in nsh_console.c *************************************************/
 
 FAR struct console_stdio_s *nsh_newconsole(void);
+int nsh_output(FAR struct nsh_vtbl_s *vtbl, FAR const char *fmt, ...);
 
 #endif /* __APPS_NSHLIB_NSH_CONSOLE_H */