Errors.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * Copyright (C) 2007 The Android Open Source Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef COCOS_ERRORS_H
  17. #define COCOS_ERRORS_H
  18. #include <sys/types.h>
  19. #include <errno.h>
  20. namespace cocos2d { namespace experimental {
  21. // use this type to return error codes
  22. #ifdef _WIN32
  23. typedef int status_t;
  24. #else
  25. typedef int32_t status_t;
  26. #endif
  27. /* the MS C runtime lacks a few error codes */
  28. /*
  29. * Error codes.
  30. * All error codes are negative values.
  31. */
  32. // Win32 #defines NO_ERROR as well. It has the same value, so there's no
  33. // real conflict, though it's a bit awkward.
  34. #ifdef _WIN32
  35. # undef NO_ERROR
  36. #endif
  37. enum {
  38. OK = 0, // Everything's swell.
  39. NO_ERROR = 0, // No errors.
  40. UNKNOWN_ERROR = (-2147483647-1), // INT32_MIN value
  41. NO_MEMORY = -ENOMEM,
  42. INVALID_OPERATION = -ENOSYS,
  43. BAD_VALUE = -EINVAL,
  44. BAD_TYPE = (UNKNOWN_ERROR + 1),
  45. NAME_NOT_FOUND = -ENOENT,
  46. PERMISSION_DENIED = -EPERM,
  47. NO_INIT = -ENODEV,
  48. ALREADY_EXISTS = -EEXIST,
  49. DEAD_OBJECT = -EPIPE,
  50. FAILED_TRANSACTION = (UNKNOWN_ERROR + 2),
  51. #if !defined(_WIN32)
  52. BAD_INDEX = -EOVERFLOW,
  53. NOT_ENOUGH_DATA = -ENODATA,
  54. WOULD_BLOCK = -EWOULDBLOCK,
  55. TIMED_OUT = -ETIMEDOUT,
  56. UNKNOWN_TRANSACTION = -EBADMSG,
  57. #else
  58. BAD_INDEX = -E2BIG,
  59. NOT_ENOUGH_DATA = (UNKNOWN_ERROR + 3),
  60. WOULD_BLOCK = (UNKNOWN_ERROR + 4),
  61. TIMED_OUT = (UNKNOWN_ERROR + 5),
  62. UNKNOWN_TRANSACTION = (UNKNOWN_ERROR + 6),
  63. #endif
  64. FDS_NOT_ALLOWED = (UNKNOWN_ERROR + 7),
  65. UNEXPECTED_NULL = (UNKNOWN_ERROR + 8),
  66. };
  67. // Restore define; enumeration is in "android" namespace, so the value defined
  68. // there won't work for Win32 code in a different namespace.
  69. #ifdef _WIN32
  70. # define NO_ERROR 0L
  71. #endif
  72. }} // namespace cocos2d { namespace experimental {
  73. // ---------------------------------------------------------------------------
  74. #endif // COCOS_ERRORS_H