• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 #pragma once
18 
19 #include <errno.h>
20 #include <stdint.h>
21 #include <sys/types.h>
22 
23 namespace android {
24 
25 /**
26  * The type used to return success/failure from frameworks APIs.
27  * See the anonymous enum below for valid values.
28  */
29 typedef int32_t status_t;
30 
31 /*
32  * Error codes.
33  * All error codes are negative values.
34  */
35 
36 // Win32 #defines NO_ERROR as well.  It has the same value, so there's no
37 // real conflict, though it's a bit awkward.
38 #ifdef _WIN32
39 # undef NO_ERROR
40 #endif
41 
42 enum {
43     OK                = 0,    // Preferred constant for checking success.
44     NO_ERROR          = OK,   // Deprecated synonym for `OK`. Prefer `OK` because it doesn't conflict with Windows.
45 
46     UNKNOWN_ERROR       = (-2147483647-1), // INT32_MIN value
47 
48     NO_MEMORY           = -ENOMEM,
49     INVALID_OPERATION   = -ENOSYS,
50     BAD_VALUE           = -EINVAL,
51     BAD_TYPE            = (UNKNOWN_ERROR + 1),
52     NAME_NOT_FOUND      = -ENOENT,
53     PERMISSION_DENIED   = -EPERM,
54     NO_INIT             = -ENODEV,
55     ALREADY_EXISTS      = -EEXIST,
56     DEAD_OBJECT         = -EPIPE,
57     FAILED_TRANSACTION  = (UNKNOWN_ERROR + 2),
58 #if !defined(_WIN32)
59     BAD_INDEX           = -EOVERFLOW,
60     NOT_ENOUGH_DATA     = -ENODATA,
61     WOULD_BLOCK         = -EWOULDBLOCK,
62     TIMED_OUT           = -ETIMEDOUT,
63     UNKNOWN_TRANSACTION = -EBADMSG,
64 #else
65     BAD_INDEX           = -E2BIG,
66     NOT_ENOUGH_DATA     = (UNKNOWN_ERROR + 3),
67     WOULD_BLOCK         = (UNKNOWN_ERROR + 4),
68     TIMED_OUT           = (UNKNOWN_ERROR + 5),
69     UNKNOWN_TRANSACTION = (UNKNOWN_ERROR + 6),
70 #endif
71     FDS_NOT_ALLOWED     = (UNKNOWN_ERROR + 7),
72     UNEXPECTED_NULL     = (UNKNOWN_ERROR + 8),
73 };
74 
75 // Restore define; enumeration is in "android" namespace, so the value defined
76 // there won't work for Win32 code in a different namespace.
77 #ifdef _WIN32
78 # define NO_ERROR 0L
79 #endif
80 
81 }  // namespace android
82