summaryrefslogtreecommitdiff
path: root/compat
diff options
context:
space:
mode:
authorRonald S. Bultje <rsbultje@gmail.com>2012-09-14 18:56:46 +0000
committerDerek Buitenhuis <derek.buitenhuis@gmail.com>2012-09-15 14:33:11 -0400
commitc1c8fdab46414e3518400d6ee18916d2444a06d7 (patch)
tree631b4bc2bf7c96ce2bd90491ff2806edf862a45f /compat
parent3f7fd59d151a2773f0e2e93e56b6b13ec6e5334b (diff)
downloadffmpeg-c1c8fdab46414e3518400d6ee18916d2444a06d7.tar.gz
compat/vsnprintf: return number of bytes required on truncation.
This conforms to C99, but requires Windows >= XP. Signed-off-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
Diffstat (limited to 'compat')
-rw-r--r--compat/msvcrt/snprintf.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/compat/msvcrt/snprintf.c b/compat/msvcrt/snprintf.c
index 2cdec74b39..0af7b54353 100644
--- a/compat/msvcrt/snprintf.c
+++ b/compat/msvcrt/snprintf.c
@@ -26,6 +26,10 @@
#include "libavutil/error.h"
+#if !defined(va_copy) && defined(_MSC_VER)
+#define va_copy(dst, src) ((dst) = (src))
+#endif
+
int avpriv_snprintf(char *s, size_t n, const char *fmt, ...)
{
va_list ap;
@@ -42,9 +46,10 @@ int avpriv_vsnprintf(char *s, size_t n, const char *fmt,
va_list ap)
{
int ret;
+ va_list ap_copy;
if (n == 0)
- return 0;
+ return _vscprintf(fmt, ap);
else if (n > INT_MAX)
return AVERROR(EOVERFLOW);
@@ -55,9 +60,11 @@ int avpriv_vsnprintf(char *s, size_t n, const char *fmt,
* _snprintf/_vsnprintf() to workaround this problem.
* See http://msdn.microsoft.com/en-us/library/1kt27hek(v=vs.80).aspx */
memset(s, 0, n);
- ret = _vsnprintf(s, n - 1, fmt, ap);
+ va_copy(ap_copy, ap);
+ ret = _vsnprintf(s, n - 1, fmt, ap_copy);
+ va_end(ap_copy);
if (ret == -1)
- ret = n;
+ ret = _vscprintf(fmt, ap);
return ret;
}