1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
/*
* Copyright (C) 2016 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "sysdeps/errno.h"
#include <errno.h>
#include <thread>
#include <unordered_map>
#include "adb.h"
#if defined(_WIN32)
#define ETXTBSY EBUSY
#endif
static std::unordered_map<int, int> initialize_translations() {
std::unordered_map<int, int> translations;
#if defined(__linux__)
#define ERRNO_VALUE(error_name, linux_value) static_assert((error_name) == (linux_value), "")
#else
#define ERRNO_VALUE(error_name, linux_value) \
translations.insert(std::make_pair((linux_value), (error_name)))
#endif
// Untranslated errno values returned by open: EDQUOT, ENODEV, ENXIO, EWOULDBLOCK
ERRNO_VALUE(EACCES, 13);
ERRNO_VALUE(EEXIST, 17);
ERRNO_VALUE(EFAULT, 14);
ERRNO_VALUE(EFBIG, 27);
ERRNO_VALUE(EINTR, 4);
ERRNO_VALUE(EINVAL, 22);
ERRNO_VALUE(EIO, 5);
ERRNO_VALUE(EISDIR, 21);
ERRNO_VALUE(ELOOP, 40);
ERRNO_VALUE(EMFILE, 24);
ERRNO_VALUE(ENAMETOOLONG, 36);
ERRNO_VALUE(ENFILE, 23);
ERRNO_VALUE(ENOENT, 2);
ERRNO_VALUE(ENOMEM, 12);
ERRNO_VALUE(ENOSPC, 28);
ERRNO_VALUE(ENOTDIR, 20);
ERRNO_VALUE(EOVERFLOW, 75);
ERRNO_VALUE(EPERM, 1);
ERRNO_VALUE(EROFS, 30);
ERRNO_VALUE(ETXTBSY, 26);
return translations;
}
int translate_linux_errno(int error) {
#if defined(__linux__)
UNUSED(initialize_translations);
return error;
#else
static std::unordered_map<int, int> translations = initialize_translations();
auto it = translations.find(error);
if (it != translations.end()) {
return it->second;
}
fatal("received unexpected remote errno: %d", error);
#endif
}
|