error_conversion.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. * Copyright (c) 2008 Allied Telesis Labs.
  3. * Copyright (c) 2012 Red Hat, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. * Author: Angus Salkeld (asalkeld@redhat.com)
  8. *
  9. * This software licensed under BSD license, the text of which follows:
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above copyright notice,
  15. * this list of conditions and the following disclaimer.
  16. * - Redistributions in binary form must reproduce the above copyright notice,
  17. * this list of conditions and the following disclaimer in the documentation
  18. * and/or other materials provided with the distribution.
  19. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  20. * contributors may be used to endorse or promote products derived from this
  21. * software without specific prior written permission.
  22. *
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  24. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  25. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  26. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  27. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  28. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  29. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  30. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  31. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  32. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  33. * THE POSSIBILITY OF SUCH DAMAGE.
  34. */
  35. #include <corosync/corotypes.h>
  36. cs_error_t qb_to_cs_error (int result)
  37. {
  38. int32_t res;
  39. cs_error_t err = CS_ERR_LIBRARY;
  40. if (result >= 0) {
  41. return CS_OK;
  42. }
  43. res = -result;
  44. switch (res) {
  45. case EBADF:
  46. err = CS_ERR_BAD_HANDLE;
  47. break;
  48. case ENOMEM:
  49. err = CS_ERR_NO_MEMORY;
  50. break;
  51. case ENOBUFS:
  52. case ETIMEDOUT:
  53. case EAGAIN:
  54. err = CS_ERR_TRY_AGAIN;
  55. break;
  56. case EBADE:
  57. err = CS_ERR_FAILED_OPERATION;
  58. break;
  59. case ETIME:
  60. err = CS_ERR_TIMEOUT;
  61. break;
  62. case EINVAL:
  63. err = CS_ERR_INVALID_PARAM;
  64. break;
  65. case EBUSY:
  66. err = CS_ERR_BUSY;
  67. break;
  68. case EACCES:
  69. err = CS_ERR_ACCESS;
  70. break;
  71. case EOVERFLOW:
  72. err = CS_ERR_NAME_TOO_LONG;
  73. break;
  74. case EEXIST:
  75. err = CS_ERR_EXIST;
  76. break;
  77. case ENOSPC:
  78. err = CS_ERR_NO_SPACE;
  79. break;
  80. case EINTR:
  81. err = CS_ERR_INTERRUPT;
  82. break;
  83. case ENOENT:
  84. case ENODEV:
  85. err = CS_ERR_NOT_EXIST;
  86. break;
  87. case ENOSYS:
  88. case ENOTSUP:
  89. err = CS_ERR_NOT_SUPPORTED;
  90. break;
  91. case EBADMSG:
  92. err = CS_ERR_MESSAGE_ERROR;
  93. break;
  94. case EMSGSIZE:
  95. case E2BIG:
  96. err = CS_ERR_TOO_BIG;
  97. break;
  98. case ECONNREFUSED:
  99. case ENOTCONN:
  100. default:
  101. err = CS_ERR_LIBRARY;
  102. break;
  103. }
  104. return err;
  105. }
  106. cs_error_t hdb_error_to_cs (int res)
  107. {
  108. if (res == 0) {
  109. return (CS_OK);
  110. } else {
  111. if (res == -EBADF) {
  112. return (CS_ERR_BAD_HANDLE);
  113. } else if (res == -ENOMEM) {
  114. return (CS_ERR_NO_MEMORY);
  115. } else if (res == -EMFILE) {
  116. return (CS_ERR_NO_RESOURCES);
  117. } else if (res == -EACCES) {
  118. return (CS_ERR_ACCESS);
  119. }
  120. return (CS_ERR_LIBRARY);
  121. }
  122. }