| Kenny Root | e2fa7dc | 2010-11-24 12:56:06 -0800 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright (C) 2010 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 __LIB_UTILS_COMPAT_H | 
|  | 18 | #define __LIB_UTILS_COMPAT_H | 
|  | 19 |  | 
|  | 20 | #include <unistd.h> | 
|  | 21 |  | 
| Elliott Hughes | cb3d653 | 2014-09-22 20:50:54 -0700 | [diff] [blame] | 22 | #if defined(__APPLE__) | 
|  | 23 |  | 
|  | 24 | /* Mac OS has always had a 64-bit off_t, so it doesn't have off64_t. */ | 
| Kenny Root | e2fa7dc | 2010-11-24 12:56:06 -0800 | [diff] [blame] | 25 |  | 
|  | 26 | typedef off_t off64_t; | 
|  | 27 |  | 
|  | 28 | static inline off64_t lseek64(int fd, off64_t offset, int whence) { | 
|  | 29 | return lseek(fd, offset, whence); | 
|  | 30 | } | 
|  | 31 |  | 
| Kenny Root | e2fa7dc | 2010-11-24 12:56:06 -0800 | [diff] [blame] | 32 | static inline ssize_t pread64(int fd, void* buf, size_t nbytes, off64_t offset) { | 
|  | 33 | return pread(fd, buf, nbytes, offset); | 
|  | 34 | } | 
| Kenny Root | e2fa7dc | 2010-11-24 12:56:06 -0800 | [diff] [blame] | 35 |  | 
| Sami Tolvanen | 8731d30 | 2015-09-28 16:43:43 +0100 | [diff] [blame] | 36 | static inline ssize_t pwrite64(int fd, const void* buf, size_t nbytes, off64_t offset) { | 
|  | 37 | return pwrite(fd, buf, nbytes, offset); | 
|  | 38 | } | 
|  | 39 |  | 
| Elliott Hughes | cb3d653 | 2014-09-22 20:50:54 -0700 | [diff] [blame] | 40 | #endif /* __APPLE__ */ | 
| Kenny Root | e2fa7dc | 2010-11-24 12:56:06 -0800 | [diff] [blame] | 41 |  | 
| Elliott Hughes | 714196d | 2015-02-03 14:26:58 -0800 | [diff] [blame] | 42 | #if defined(_WIN32) | 
| Dan Albert | c6b30f3 | 2015-03-26 23:22:56 -0700 | [diff] [blame] | 43 | #define O_CLOEXEC O_NOINHERIT | 
| Elliott Hughes | 714196d | 2015-02-03 14:26:58 -0800 | [diff] [blame] | 44 | #define O_NOFOLLOW 0 | 
|  | 45 | #define DEFFILEMODE 0666 | 
|  | 46 | #endif /* _WIN32 */ | 
|  | 47 |  | 
| Elliott Hughes | 146c244 | 2015-04-03 12:53:36 -0700 | [diff] [blame] | 48 | #define ZD "%zd" | 
|  | 49 | #define ZD_TYPE ssize_t | 
| Kenny Root | b9fd6f9 | 2012-10-16 11:34:02 -0700 | [diff] [blame] | 50 |  | 
|  | 51 | /* | 
| Dan Albert | e4c649c | 2014-11-20 10:47:55 -0800 | [diff] [blame] | 52 | * Needed for cases where something should be constexpr if possible, but not | 
|  | 53 | * being constexpr is fine if in pre-C++11 code (such as a const static float | 
|  | 54 | * member variable). | 
|  | 55 | */ | 
|  | 56 | #if __cplusplus >= 201103L | 
|  | 57 | #define CONSTEXPR constexpr | 
|  | 58 | #else | 
|  | 59 | #define CONSTEXPR | 
|  | 60 | #endif | 
|  | 61 |  | 
|  | 62 | /* | 
| Kenny Root | b9fd6f9 | 2012-10-16 11:34:02 -0700 | [diff] [blame] | 63 | * TEMP_FAILURE_RETRY is defined by some, but not all, versions of | 
|  | 64 | * <unistd.h>. (Alas, it is not as standard as we'd hoped!) So, if it's | 
|  | 65 | * not already defined, then define it here. | 
|  | 66 | */ | 
|  | 67 | #ifndef TEMP_FAILURE_RETRY | 
|  | 68 | /* Used to retry syscalls that can return EINTR. */ | 
|  | 69 | #define TEMP_FAILURE_RETRY(exp) ({         \ | 
|  | 70 | typeof (exp) _rc;                      \ | 
|  | 71 | do {                                   \ | 
|  | 72 | _rc = (exp);                       \ | 
|  | 73 | } while (_rc == -1 && errno == EINTR); \ | 
|  | 74 | _rc; }) | 
|  | 75 | #endif | 
|  | 76 |  | 
| Elliott Hughes | 1f8bc86 | 2015-07-29 14:02:29 -0700 | [diff] [blame] | 77 | #if defined(_WIN32) | 
|  | 78 | #define OS_PATH_SEPARATOR '\\' | 
|  | 79 | #else | 
|  | 80 | #define OS_PATH_SEPARATOR '/' | 
|  | 81 | #endif | 
|  | 82 |  | 
| Kenny Root | e2fa7dc | 2010-11-24 12:56:06 -0800 | [diff] [blame] | 83 | #endif /* __LIB_UTILS_COMPAT_H */ |