error_conversion.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 ETIMEDOUT:
  52. case EAGAIN:
  53. err = CS_ERR_TRY_AGAIN;
  54. break;
  55. case EBADE:
  56. err = CS_ERR_FAILED_OPERATION;
  57. break;
  58. case ETIME:
  59. err = CS_ERR_TIMEOUT;
  60. break;
  61. case EINVAL:
  62. err = CS_ERR_INVALID_PARAM;
  63. break;
  64. case EBUSY:
  65. err = CS_ERR_BUSY;
  66. break;
  67. case EACCES:
  68. err = CS_ERR_ACCESS;
  69. break;
  70. case EOVERFLOW:
  71. err = CS_ERR_NAME_TOO_LONG;
  72. break;
  73. case EEXIST:
  74. err = CS_ERR_EXIST;
  75. break;
  76. case ENOBUFS:
  77. err = CS_ERR_QUEUE_FULL;
  78. break;
  79. case ENOSPC:
  80. err = CS_ERR_NO_SPACE;
  81. break;
  82. case EINTR:
  83. err = CS_ERR_INTERRUPT;
  84. break;
  85. case ENOENT:
  86. case ENODEV:
  87. err = CS_ERR_NOT_EXIST;
  88. break;
  89. case ENOSYS:
  90. case ENOTSUP:
  91. err = CS_ERR_NOT_SUPPORTED;
  92. break;
  93. case EBADMSG:
  94. err = CS_ERR_MESSAGE_ERROR;
  95. break;
  96. case EMSGSIZE:
  97. case E2BIG:
  98. err = CS_ERR_TOO_BIG;
  99. break;
  100. case ECONNREFUSED:
  101. case ENOTCONN:
  102. default:
  103. err = CS_ERR_LIBRARY;
  104. break;
  105. }
  106. return err;
  107. }
  108. cs_error_t hdb_error_to_cs (int res)
  109. {
  110. if (res == 0) {
  111. return (CS_OK);
  112. } else {
  113. if (res == -EBADF) {
  114. return (CS_ERR_BAD_HANDLE);
  115. } else if (res == -ENOMEM) {
  116. return (CS_ERR_NO_MEMORY);
  117. } else if (res == -EMFILE) {
  118. return (CS_ERR_NO_RESOURCES);
  119. } else if (res == -EACCES) {
  120. return (CS_ERR_ACCESS);
  121. }
  122. return (CS_ERR_LIBRARY);
  123. }
  124. }