ua_log_socket_error.h 895 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. /* This work is licensed under a Creative Commons CCZero 1.0 Universal License.
  2. * See http://creativecommons.org/publicdomain/zero/1.0/ for more information.
  3. *
  4. * Copyright 2017 (c) Stefan Profanter, fortiss GmbH
  5. */
  6. #ifndef UA_LOG_SOCKET_ERROR_H_
  7. #define UA_LOG_SOCKET_ERROR_H_
  8. #ifdef __cplusplus
  9. extern "C" {
  10. #endif
  11. #ifdef _WIN32
  12. #include <winsock2.h>
  13. #define UA_LOG_SOCKET_ERRNO_WRAP(LOG) { \
  14. char *errno_str = NULL; \
  15. FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, \
  16. NULL, WSAGetLastError(), \
  17. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), \
  18. (LPSTR)&errno_str, 0, NULL); \
  19. LOG; \
  20. LocalFree(errno_str); \
  21. }
  22. #else
  23. #define UA_LOG_SOCKET_ERRNO_WRAP(LOG) { \
  24. char *errno_str = strerror(errno); \
  25. LOG; \
  26. }
  27. #endif
  28. #ifdef __cplusplus
  29. } // extern "C"
  30. #endif
  31. #endif /* UA_LOG_SOCKET_ERROR_H_ */