You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

snprintf_compat.h 847 B

123456789101112131415161718192021222324252627282930313233343536
  1. #ifndef __snprintf_compat_h
  2. #define __snprintf_compat_h
  3. /*
  4. * Microsoft's _vsnprintf and _snprint don't always terminate
  5. * the string, so use wrappers that ensure that.
  6. */
  7. #include <stdarg.h>
  8. #if !defined(HAVE_SNPRINTF) && defined(_MSC_VER)
  9. static int json_c_vsnprintf(char *str, size_t size, const char *format, va_list ap)
  10. {
  11. int ret;
  12. ret = _vsnprintf(str, size, format, ap);
  13. str[size - 1] = '\0';
  14. return ret;
  15. }
  16. #define vsnprintf json_c_vsnprintf
  17. static int json_c_snprintf(char *str, size_t size, const char *format, ...)
  18. {
  19. va_list ap;
  20. int ret;
  21. va_start(ap, format);
  22. ret = json_c_vsnprintf(str, size, format, ap);
  23. va_end(ap);
  24. return ret;
  25. }
  26. #define snprintf json_c_snprintf
  27. #elif !defined(HAVE_SNPRINTF) /* !HAVE_SNPRINTF */
  28. # error Need vsnprintf!
  29. #endif /* !HAVE_SNPRINTF && defined(WIN32) */
  30. #endif /* __snprintf_compat_h */