| 1 | /* |
| 2 | * Copyright (C) 2011 David Goulet <dgoulet@efficios.com> |
| 3 | * |
| 4 | * SPDX-License-Identifier: LGPL-2.1-only |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | #ifndef _COMPAT_FCNTL_H |
| 9 | #define _COMPAT_FCNTL_H |
| 10 | |
| 11 | #include <common/compat/errno.hpp> |
| 12 | |
| 13 | #include <fcntl.h> |
| 14 | #include <sys/types.h> |
| 15 | |
| 16 | static_assert(sizeof(off_t) == sizeof(int64_t), |
| 17 | "Build system is misconfigured, off_t must be 64-bit wide"); |
| 18 | |
| 19 | #if (defined(__FreeBSD__) || defined(__sun__)) |
| 20 | typedef off64_t loff_t; |
| 21 | #endif |
| 22 | |
| 23 | #ifdef __linux__ |
| 24 | extern int compat_sync_file_range(int fd, off_t offset, off_t nbytes, unsigned int flags); |
| 25 | #define lttng_sync_file_range(fd, offset, nbytes, flags) \ |
| 26 | compat_sync_file_range(fd, offset, nbytes, flags) |
| 27 | |
| 28 | #endif /* __linux__ */ |
| 29 | |
| 30 | #if (defined(__FreeBSD__) || defined(__CYGWIN__) || defined(__sun__)) |
| 31 | /* |
| 32 | * Possible flags under Linux. Simply nullify them and avoid wrapper. |
| 33 | */ |
| 34 | #define SYNC_FILE_RANGE_WAIT_AFTER 0 |
| 35 | #define SYNC_FILE_RANGE_WAIT_BEFORE 0 |
| 36 | #define SYNC_FILE_RANGE_WRITE 0 |
| 37 | |
| 38 | static inline int lttng_sync_file_range(int fd __attribute__((unused)), |
| 39 | off_t offset __attribute__((unused)), |
| 40 | off_t nbytes __attribute__((unused)), |
| 41 | unsigned int flags __attribute__((unused))) |
| 42 | { |
| 43 | return -ENOSYS; |
| 44 | } |
| 45 | #endif |
| 46 | |
| 47 | #if (defined(__FreeBSD__) || defined(__CYGWIN__) || defined(__sun__)) |
| 48 | /* |
| 49 | * Possible flags under Linux. Simply nullify them and avoid wrappers. |
| 50 | */ |
| 51 | #define SPLICE_F_MOVE 0 |
| 52 | #define SPLICE_F_NONBLOCK 0 |
| 53 | #define SPLICE_F_MORE 0 |
| 54 | #define SPLICE_F_GIFT 0 |
| 55 | |
| 56 | static inline ssize_t splice(int fd_in __attribute__((unused)), |
| 57 | loff_t *off_in __attribute__((unused)), |
| 58 | int fd_out __attribute__((unused)), |
| 59 | loff_t *off_out __attribute__((unused)), |
| 60 | size_t len __attribute__((unused)), |
| 61 | unsigned int flags __attribute__((unused))) |
| 62 | { |
| 63 | return -ENOSYS; |
| 64 | } |
| 65 | #endif |
| 66 | |
| 67 | #if !(defined(__linux__) || defined(__FreeBSD__) || defined(__CYGWIN__) || defined(__sun__) || \ |
| 68 | defined(__APPLE__)) |
| 69 | #error "Please add support for your OS." |
| 70 | #endif /* __linux__ , __FreeBSD__, __CYGWIN__, __sun__, __APPLE__ */ |
| 71 | |
| 72 | #endif /* _COMPAT_FCNTL_H */ |