summaryrefslogtreecommitdiff
path: root/utils/ErrorUtils.cpp (plain)
blob: 28f19a64ff0d1d07bea87384e7e2703a209cf7a9
1/*
2 * Copyright (C) 2011 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
18#include "ErrorUtils.h"
19
20namespace android {
21
22/**
23 @brief Method to convert from POSIX to Android errors
24
25 @param error Any of the standard POSIX error codes (defined in bionic/libc/kernel/common/asm-generic/errno.h)
26 @return Any of the standard Android error code (defined in frameworks/base/include/utils/Errors.h)
27 */
28status_t ErrorUtils::posixToAndroidError(int error)
29{
30 switch(error)
31 {
32 case 0:
33 return NO_ERROR;
34 case EINVAL:
35 case EFBIG:
36 case EMSGSIZE:
37 case E2BIG:
38 case EFAULT:
39 case EILSEQ:
40 return BAD_VALUE;
41 case ENOSYS:
42 return INVALID_OPERATION;
43 case EACCES:
44 case EPERM:
45 return PERMISSION_DENIED;
46 case EADDRINUSE:
47 case EAGAIN:
48 case EALREADY:
49 case EBUSY:
50 case EEXIST:
51 case EINPROGRESS:
52 return ALREADY_EXISTS;
53 case ENOMEM:
54 return NO_MEMORY;
55 default:
56 return UNKNOWN_ERROR;
57 };
58
59 return NO_ERROR;
60}
61
62};
63
64
65
66