srt_compat.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * SRT - Secure, Reliable, Transport
  3. * Copyright (c) 2018 Haivision Systems Inc.
  4. *
  5. * This Source Code Form is subject to the terms of the Mozilla Public
  6. * License, v. 2.0. If a copy of the MPL was not distributed with this
  7. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  8. *
  9. */
  10. /*****************************************************************************
  11. written by
  12. Haivision Systems Inc.
  13. *****************************************************************************/
  14. #ifndef INC_SRT_COMPAT_H
  15. #define INC_SRT_COMPAT_H
  16. #include <stddef.h>
  17. #include <time.h>
  18. #ifndef SRT_API
  19. #ifdef _WIN32
  20. #ifndef __MINGW32__
  21. #ifdef SRT_DYNAMIC
  22. #ifdef SRT_EXPORTS
  23. #define SRT_API __declspec(dllexport)
  24. #else
  25. #define SRT_API __declspec(dllimport)
  26. #endif
  27. #else
  28. #define SRT_API
  29. #endif
  30. #else
  31. #define SRT_API
  32. #endif
  33. #else
  34. #define SRT_API __attribute__ ((visibility("default")))
  35. #endif
  36. #endif
  37. #ifdef _WIN32
  38. // https://msdn.microsoft.com/en-us/library/tcxf1dw6.aspx
  39. // printf() Format for ssize_t
  40. #if !defined(PRIzd)
  41. #define PRIzd "Id"
  42. #endif
  43. // printf() Format for size_t
  44. #if !defined(PRIzu)
  45. #define PRIzu "Iu"
  46. #endif
  47. #else
  48. // http://www.gnu.org/software/libc/manual/html_node/Integer-Conversions.html
  49. // printf() Format for ssize_t
  50. #if !defined(PRIzd)
  51. #define PRIzd "zd"
  52. #endif
  53. // printf() Format for size_t
  54. #if !defined(PRIzu)
  55. #define PRIzu "zu"
  56. #endif
  57. #endif
  58. #ifdef __cplusplus
  59. extern "C" {
  60. #endif
  61. /* Ensures that we store the error in the buffer and return the bufer. */
  62. SRT_API const char * SysStrError(int errnum, char * buf, size_t buflen);
  63. #ifdef __cplusplus
  64. } // extern C
  65. // Extra C++ stuff. Included only in C++ mode.
  66. #include <string>
  67. #include <cstring>
  68. inline std::string SysStrError(int errnum)
  69. {
  70. char buf[1024];
  71. return SysStrError(errnum, buf, 1024);
  72. }
  73. inline struct tm SysLocalTime(time_t tt)
  74. {
  75. struct tm tms;
  76. memset(&tms, 0, sizeof tms);
  77. #ifdef _WIN32
  78. errno_t rr = localtime_s(&tms, &tt);
  79. if (rr == 0)
  80. return tms;
  81. #else
  82. // Ignore the error, state that if something
  83. // happened, you simply have a pre-cleared tms.
  84. localtime_r(&tt, &tms);
  85. #endif
  86. return tms;
  87. }
  88. #endif // defined C++
  89. #endif // INC_SRT_COMPAT_H