win32.h 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #ifndef _WIN32_HELPER_INCLUDE
  2. #define _WIN32_HELPER_INCLUDE
  3. #ifdef _MSC_VER
  4. #include <winsock2.h> /* for struct timeval */
  5. #ifndef inline
  6. #define inline __inline
  7. #endif
  8. #ifndef strcasecmp
  9. #define strcasecmp stricmp
  10. #endif
  11. #ifndef strncasecmp
  12. #define strncasecmp strnicmp
  13. #endif
  14. #ifndef va_copy
  15. #define va_copy(d,s) ((d) = (s))
  16. #endif
  17. #ifndef snprintf
  18. #define snprintf c99_snprintf
  19. __inline int c99_vsnprintf(char* str, size_t size, const char* format, va_list ap)
  20. {
  21. int count = -1;
  22. if (size != 0)
  23. count = _vsnprintf_s(str, size, _TRUNCATE, format, ap);
  24. if (count == -1)
  25. count = _vscprintf(format, ap);
  26. return count;
  27. }
  28. __inline int c99_snprintf(char* str, size_t size, const char* format, ...)
  29. {
  30. int count;
  31. va_list ap;
  32. va_start(ap, format);
  33. count = c99_vsnprintf(str, size, format, ap);
  34. va_end(ap);
  35. return count;
  36. }
  37. #endif
  38. #endif /* _MSC_VER */
  39. #ifdef _WIN32
  40. #define strerror_r(errno,buf,len) strerror_s(buf,len,errno)
  41. #endif /* _WIN32 */
  42. #endif /* _WIN32_HELPER_INCLUDE */