opener_error.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /*******************************************************************************
  2. * Copyright (c) 2009, Rockwell Automation, Inc.
  3. * All rights reserved.
  4. *
  5. ******************************************************************************/
  6. /** @file POSIX/opener_error.c
  7. * @author Martin Melik Merkumians
  8. * @brief This file includes the prototypes for error resolution functions like strerror or WSAGetLastError
  9. *
  10. */
  11. #undef _GNU_SOURCE /* Force the use of the XSI compliant strerror_r() function. */
  12. #include <errno.h>
  13. #include <stddef.h>
  14. #include <stdlib.h>
  15. #include <string.h>
  16. #include "opener_error.h"
  17. /* There are some places where the memory is not freed */
  18. static char kErrorMessageBuffer[256];
  19. int GetSocketErrorNumber(void) {
  20. return errno;
  21. }
  22. char* GetErrorMessage(int error_number) {
  23. const char *error_message = strerror(error_number);
  24. strncpy(kErrorMessageBuffer, error_message, sizeof(kErrorMessageBuffer) - 1);
  25. kErrorMessageBuffer[sizeof(kErrorMessageBuffer) - 1] = '\0';
  26. return kErrorMessageBuffer;
  27. }
  28. void FreeErrorMessage(char *error_message) {
  29. (void)error_message;
  30. }