snprintf.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #ifndef _PORTABLE_SNPRINTF_H_
  2. #define _PORTABLE_SNPRINTF_H_
  3. #define PORTABLE_SNPRINTF_VERSION_MAJOR 2
  4. #define PORTABLE_SNPRINTF_VERSION_MINOR 2
  5. #include "os.h"
  6. #if defined(IS_MACOSX)
  7. #define HAVE_SNPRINTF
  8. #else
  9. #define HAVE_SNPRINTF
  10. #define PREFER_PORTABLE_SNPRINTF
  11. #endif
  12. #include <stddef.h>
  13. #include <stdarg.h>
  14. #ifdef __cplusplus
  15. extern "C"
  16. {
  17. #endif
  18. #ifdef HAVE_SNPRINTF
  19. #include <stdio.h>
  20. #else
  21. extern int snprintf(char *, size_t, const char *, /*args*/ ...);
  22. extern int vsnprintf(char *, size_t, const char *, va_list);
  23. #endif
  24. #if defined(HAVE_SNPRINTF) && defined(PREFER_PORTABLE_SNPRINTF)
  25. extern int portable_snprintf(char *str, size_t str_m, const char *fmt, /*args*/ ...);
  26. extern int portable_vsnprintf(char *str, size_t str_m, const char *fmt, va_list ap);
  27. #define snprintf portable_snprintf
  28. #define vsnprintf portable_vsnprintf
  29. #endif
  30. extern int asprintf (char **ptr, const char *fmt, /*args*/ ...);
  31. extern int vasprintf (char **ptr, const char *fmt, va_list ap);
  32. extern int asnprintf (char **ptr, size_t str_m, const char *fmt, /*args*/ ...);
  33. extern int vasnprintf(char **ptr, size_t str_m, const char *fmt, va_list ap);
  34. #endif
  35. #ifdef __cplusplus
  36. }
  37. #endif