snprintf.c 801 B

123456789101112131415161718192021222324252627282930313233343536373839
  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. count = _vsnprintf_s(str, size, _TRUNCATE, format, ap);
  16. if (count == -1)
  17. count = _vscprintf(format, ap);
  18. return count;
  19. }
  20. int _TIFF_snprintf_f(char* str, size_t size, const char* format, ...)
  21. {
  22. int count;
  23. va_list ap;
  24. va_start(ap, format);
  25. count = vsnprintf(str, size, format, ap);
  26. va_end(ap);
  27. return count;
  28. }
  29. #endif // _MSC_VER