File: abi_compatibility.cpp

package info (click to toggle)
android-platform-tools 35.0.2-1~exp6
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 211,716 kB
  • sloc: cpp: 995,749; java: 290,495; ansic: 145,647; xml: 58,531; python: 39,608; sh: 14,500; javascript: 5,198; asm: 4,866; makefile: 3,115; yacc: 769; awk: 368; ruby: 183; sql: 140; perl: 88; lex: 67
file content (89 lines) | stat: -rw-r--r-- 2,999 bytes parent folder | download | duplicates (3)
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
 * Copyright (C) 2019 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 <memory>

#include "android-base/cmsg.h"
#include "android-base/file.h"
#include "android-base/mapped_file.h"
#include "android-base/unique_fd.h"

namespace android {
namespace base {

// These ABI-compatibility shims are in a separate file for two reasons:
//   1. If they were in the file with the actual functions, it prevents calls to
//      those functions by other functions in the file, due to ambiguity.
//   2. We will hopefully be able to delete these quickly.

#if !defined(_WIN32)
ssize_t SendFileDescriptorVector(int sockfd, const void* data, size_t len,
                                 const std::vector<int>& fds) {
  return SendFileDescriptorVector(borrowed_fd(sockfd), data, len, fds);
}

ssize_t ReceiveFileDescriptorVector(int sockfd, void* data, size_t len, size_t max_fds,
                                    std::vector<unique_fd>* fds) {
  return ReceiveFileDescriptorVector(borrowed_fd(sockfd), data, len, max_fds, fds);
}
#endif

bool ReadFdToString(int fd, std::string* content) {
  return ReadFdToString(borrowed_fd(fd), content);
}

bool WriteStringToFd(const std::string& content, int fd) {
  return WriteStringToFd(std::string_view(content), borrowed_fd(fd));
}

bool WriteStringToFd(const std::string& content, borrowed_fd fd) {
  return WriteStringToFd(std::string_view(content), fd);
}

bool ReadFully(int fd, void* data, size_t byte_count) {
  return ReadFully(borrowed_fd(fd), data, byte_count);
}

bool ReadFullyAtOffset(int fd, void* data, size_t byte_count, off64_t offset) {
  return ReadFullyAtOffset(borrowed_fd(fd), data, byte_count, offset);
}

bool WriteFully(int fd, const void* data, size_t byte_count) {
  return WriteFully(borrowed_fd(fd), data, byte_count);
}

std::string Basename(const std::string& path) {
  return Basename(std::string_view(path));
}

std::string Dirname(const std::string& path) {
  return Dirname(std::string_view(path));
}

#if defined(__LP64__)
#define MAPPEDFILE_FROMFD _ZN10MappedFile6FromFdEilmi
#else
#define MAPPEDFILE_FROMFD _ZN10MappedFile6FromFdEixmi
#endif

#pragma clang diagnostic ignored "-Wreturn-type-c-linkage"
extern "C" std::unique_ptr<MappedFile> MAPPEDFILE_FROMFD(int fd, off64_t offset, size_t length,
                                                         int prot) {
  return MappedFile::FromFd(fd, offset, length, prot);
}

}  // namespace base
}  // namespace android