1 /******************************************************************************
2 *
3 * Copyright (C) 2022 Google, Inc.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 ******************************************************************************/
18
19 #include "hal/syscall_wrapper_impl.h"
20
21 #include <unistd.h>
22
23 #include <cerrno>
24
25 namespace bluetooth {
26 namespace hal {
27
Socket(int domain,int type,int protocol)28 int SyscallWrapperImpl::Socket(int domain, int type, int protocol) {
29 int ret = socket(domain, type, protocol);
30 errno_ = errno;
31 return ret;
32 }
33
Bind(int fd,const struct sockaddr * addr,socklen_t len)34 int SyscallWrapperImpl::Bind(int fd, const struct sockaddr* addr, socklen_t len) {
35 int ret = bind(fd, addr, len);
36 errno_ = errno;
37 return ret;
38 }
39
Connect(int fd,const struct sockaddr * addr,socklen_t len)40 int SyscallWrapperImpl::Connect(int fd, const struct sockaddr* addr, socklen_t len) {
41 int ret = connect(fd, addr, len);
42 errno_ = errno;
43 return ret;
44 }
45
Send(int fd,const void * buf,size_t n,int flags)46 ssize_t SyscallWrapperImpl::Send(int fd, const void* buf, size_t n, int flags) {
47 int ret = send(fd, buf, n, flags);
48 errno_ = errno;
49 return ret;
50 }
51
Recv(int fd,void * buf,size_t n,int flags)52 ssize_t SyscallWrapperImpl::Recv(int fd, void* buf, size_t n, int flags) {
53 int ret = recv(fd, buf, n, flags);
54 errno_ = errno;
55 return ret;
56 }
57
Setsockopt(int fd,int level,int optname,const void * optval,socklen_t optlen)58 int SyscallWrapperImpl::Setsockopt(int fd, int level, int optname, const void* optval,
59 socklen_t optlen) {
60 int ret = setsockopt(fd, level, optname, optval, optlen);
61 errno_ = errno;
62 return ret;
63 }
64
Listen(int fd,int n)65 int SyscallWrapperImpl::Listen(int fd, int n) {
66 int ret = listen(fd, n);
67 errno_ = errno;
68 return ret;
69 }
70
Accept(int fd,struct sockaddr * addr,socklen_t * addr_len,int flags)71 int SyscallWrapperImpl::Accept(int fd, struct sockaddr* addr, socklen_t* addr_len, int flags) {
72 int ret = accept4(fd, addr, addr_len, flags);
73 errno_ = errno;
74 return ret;
75 }
76
Write(int fd,const void * buf,size_t count)77 ssize_t SyscallWrapperImpl::Write(int fd, const void* buf, size_t count) {
78 ssize_t ret = write(fd, buf, count);
79 errno_ = errno;
80 return ret;
81 }
82
Close(int fd)83 int SyscallWrapperImpl::Close(int fd) {
84 int ret = close(fd);
85 errno_ = errno;
86 return ret;
87 }
88
Pipe2(int * pipefd,int flags)89 int SyscallWrapperImpl::Pipe2(int* pipefd, int flags) {
90 int ret = pipe2(pipefd, flags);
91 errno_ = errno;
92 return ret;
93 }
94
GetErrno() const95 int SyscallWrapperImpl::GetErrno() const { return errno_; }
96
Poll(struct pollfd * fds,nfds_t nfds,int timeout)97 int SyscallWrapperImpl::Poll(struct pollfd* fds, nfds_t nfds, int timeout) {
98 int ret = poll(fds, nfds, timeout);
99 errno_ = errno;
100 return ret;
101 }
102
103 } // namespace hal
104 } // namespace bluetooth
105