error_conversion.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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. }
  123. const char * cs_strerror(cs_error_t err)
  124. {
  125. switch (err) {
  126. case CS_OK:
  127. return "success";
  128. case CS_ERR_LIBRARY:
  129. return "CS_ERR_LIBRARY";
  130. case CS_ERR_VERSION:
  131. return "CS_ERR_VERSION";
  132. case CS_ERR_INIT:
  133. return "CS_ERR_INIT";
  134. case CS_ERR_NO_MEMORY:
  135. return "CS_ERR_NO_MEMORY";
  136. case CS_ERR_NAME_TOO_LONG :
  137. return "CS_ERR_NAME_TOO_LONG ";
  138. case CS_ERR_TIMEOUT:
  139. return "CS_ERR_TIMEOUT";
  140. case CS_ERR_TRY_AGAIN:
  141. return "CS_ERR_TRY_AGAIN";
  142. case CS_ERR_INVALID_PARAM:
  143. return "CS_ERR_INVALID_PARAM";
  144. case CS_ERR_BAD_HANDLE:
  145. return "CS_ERR_BAD_HANDLE";
  146. case CS_ERR_BUSY :
  147. return "CS_ERR_BUSY ";
  148. case CS_ERR_ACCESS :
  149. return "CS_ERR_ACCESS ";
  150. case CS_ERR_NOT_EXIST :
  151. return "CS_ERR_NOT_EXIST ";
  152. case CS_ERR_EXIST :
  153. return "CS_ERR_EXIST ";
  154. case CS_ERR_NO_SPACE :
  155. return "CS_ERR_NO_SPACE ";
  156. case CS_ERR_INTERRUPT :
  157. return "CS_ERR_INTERRUPT ";
  158. case CS_ERR_NAME_NOT_FOUND :
  159. return "CS_ERR_NAME_NOT_FOUND ";
  160. case CS_ERR_NO_RESOURCES :
  161. return "CS_ERR_NO_RESOURCES ";
  162. case CS_ERR_NOT_SUPPORTED :
  163. return "CS_ERR_NOT_SUPPORTED ";
  164. case CS_ERR_BAD_OPERATION :
  165. return "CS_ERR_BAD_OPERATION ";
  166. case CS_ERR_FAILED_OPERATION :
  167. return "CS_ERR_FAILED_OPERATION ";
  168. case CS_ERR_MESSAGE_ERROR :
  169. return "CS_ERR_MESSAGE_ERROR ";
  170. case CS_ERR_QUEUE_FULL :
  171. return "CS_ERR_QUEUE_FULL ";
  172. case CS_ERR_QUEUE_NOT_AVAILABLE :
  173. return "CS_ERR_QUEUE_NOT_AVAILABLE ";
  174. case CS_ERR_BAD_FLAGS :
  175. return "CS_ERR_BAD_FLAGS ";
  176. case CS_ERR_TOO_BIG :
  177. return "CS_ERR_TOO_BIG ";
  178. case CS_ERR_NO_SECTIONS :
  179. return "CS_ERR_NO_SECTIONS ";
  180. case CS_ERR_CONTEXT_NOT_FOUND :
  181. return "CS_ERR_CONTEXT_NOT_FOUND ";
  182. case CS_ERR_TOO_MANY_GROUPS :
  183. return "CS_ERR_TOO_MANY_GROUPS ";
  184. case CS_ERR_SECURITY :
  185. return "CS_ERR_SECURITY ";
  186. default:
  187. return "unknown error";
  188. }
  189. }