1 /*
2 * Copyright (C) 2012 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 #ifndef PORTABILITY_H_included
18 #define PORTABILITY_H_included
19
20 #include <byteswap.h>
21 #include <sys/sendfile.h>
22 #include <sys/statvfs.h>
23
24 #include <netdb.h>
25 #if defined(__BIONIC__)
26 extern "C" int android_getaddrinfofornet(const char*, const char*, const struct addrinfo*, unsigned, unsigned, struct addrinfo**);
27 #else
android_getaddrinfofornet(const char * hostname,const char * servname,const struct addrinfo * hints,unsigned,unsigned,struct addrinfo ** res)28 static inline int android_getaddrinfofornet(const char* hostname, const char* servname,
29 const struct addrinfo* hints, unsigned /*netid*/, unsigned /*mark*/, struct addrinfo** res) {
30 return getaddrinfo(hostname, servname, hints, res);
31 }
32 #endif
33
34 #if __has_include(<linux/vm_sockets.h>)
35 #include <linux/vm_sockets.h>
36 #else // __has_include(<linux/vm_sockets.h>)
37 // the platform does not support virtio-vsock
38 #define AF_VSOCK (-1)
39 #define VMADDR_PORT_ANY (-1)
40 #define VMADDR_CID_ANY (-1)
41 #define VMADDR_CID_LOCAL (-1)
42 #define VMADDR_CID_HOST (-1)
43 #endif // __has_include(<linux/vm_sockets.h>)
44
45 #if defined(__GLIBC__) && !defined(__LP64__)
46
47 #include <unistd.h>
48
49 // 32 bit GLIBC hardcodes a "long int" as the return type for
50 // TEMP_FAILURE_RETRY so the return value here gets truncated for
51 // functions that return 64 bit types.
52 #undef TEMP_FAILURE_RETRY
53 #define TEMP_FAILURE_RETRY(exp) ({ \
54 __typeof__(exp) _rc; \
55 do { \
56 _rc = (exp); \
57 } while (_rc == -1 && errno == EINTR); \
58 _rc; })
59
60 #endif // __GLIBC__ && !__LP64__
61
62 #endif // PORTABILITY_H_included
63