snprintf.c 882 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /**
  2. * Workaround for lack of snprintf(3) in Visual Studio. See
  3. * http://stackoverflow.com/questions/2915672/snprintf-and-visual-studio-2010/8712996#8712996
  4. * It's a trivial wrapper around the builtin _vsnprintf_s and
  5. * _vscprintf functions.
  6. */
  7. #ifdef _MSC_VER
  8. #include <stdio.h>
  9. #include <stdarg.h>
  10. #include "libport.h"
  11. int _TIFF_vsnprintf_f(char* str, size_t size, const char* format, va_list ap)
  12. {
  13. int count = -1;
  14. if (size != 0)
  15. #if _MSC_VER <= 1310
  16. count = _vsnprintf(str, size, format, ap);
  17. #else
  18. count = _vsnprintf_s(str, size, _TRUNCATE, format, ap);
  19. #endif
  20. if (count == -1)
  21. count = _vscprintf(format, ap);
  22. return count;
  23. }
  24. int _TIFF_snprintf_f(char* str, size_t size, const char* format, ...)
  25. {
  26. int count;
  27. va_list ap;
  28. va_start(ap, format);
  29. count = vsnprintf(str, size, format, ap);
  30. va_end(ap);
  31. return count;
  32. }
  33. #endif // _MSC_VER