summaryrefslogtreecommitdiff
path: root/src/libvterm
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2017-07-11 22:34:51 +0200
committerBram Moolenaar <Bram@vim.org>2017-07-11 22:34:51 +0200
commit8327d1df1754b33d8a93b3411f30692f0042f4ce (patch)
tree6f2d59fd480125984eef99d22941edc37f23d31c /src/libvterm
parent292eff0c5aacb8531d65509679b6c29eae8dc22a (diff)
downloadvim-git-8327d1df1754b33d8a93b3411f30692f0042f4ce.tar.gz
patch 8.0.0709: libvterm cannot use vsnprintf()v8.0.0709
Problem: Libvterm cannot use vsnprintf(), it does not exist in C90. Solution: Use vim_vsnprintf() instead.
Diffstat (limited to 'src/libvterm')
-rw-r--r--src/libvterm/src/vterm.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/libvterm/src/vterm.c b/src/libvterm/src/vterm.c
index 8dca1b256..2931e5202 100644
--- a/src/libvterm/src/vterm.c
+++ b/src/libvterm/src/vterm.c
@@ -130,16 +130,42 @@ static int outbuffer_is_full(VTerm *vt)
return vt->outbuffer_cur >= vt->outbuffer_len - 1;
}
+#if _XOPEN_SOURCE >= 500 || _ISOC99_SOURCE || _BSD_SOURCE
+# undef VSNPRINTF
+# define VSNPRINTF vsnprintf
+#else
+# ifdef VSNPRINTF
+/* Use a provided vsnprintf() function. */
+int VSNPRINTF(char *str, size_t str_m, const char *fmt, va_list ap);
+# endif
+#endif
+
+
INTERNAL void vterm_push_output_vsprintf(VTerm *vt, const char *format, va_list args)
{
int written;
+#ifndef VSNPRINTF
+ /* When vsnprintf() is not available (C90) fall back to vsprintf(). */
char buffer[1024]; /* 1Kbyte is enough for everybody, right? */
+#endif
if(outbuffer_is_full(vt)) {
DEBUG_LOG("vterm_push_output(): buffer overflow; truncating output\n");
return;
}
+#ifdef VSNPRINTF
+ written = VSNPRINTF(vt->outbuffer + vt->outbuffer_cur,
+ vt->outbuffer_len - vt->outbuffer_cur,
+ format, args);
+
+ if(written == (int)(vt->outbuffer_len - vt->outbuffer_cur)) {
+ /* output was truncated */
+ vt->outbuffer_cur = vt->outbuffer_len - 1;
+ }
+ else
+ vt->outbuffer_cur += written;
+#else
written = vsprintf(buffer, format, args);
if(written >= (int)(vt->outbuffer_len - vt->outbuffer_cur)) {
@@ -151,6 +177,7 @@ INTERNAL void vterm_push_output_vsprintf(VTerm *vt, const char *format, va_list
strncpy(vt->outbuffer + vt->outbuffer_cur, buffer, written + 1);
vt->outbuffer_cur += written;
}
+#endif
}
INTERNAL void vterm_push_output_sprintf(VTerm *vt, const char *format, ...)