Andrew Geissler | c5535c9 | 2023-01-27 16:10:19 -0600 | [diff] [blame] | 1 | From 74b3844737b03492756b4f896c938b504b069f14 Mon Sep 17 00:00:00 2001 |
| 2 | From: Jérémie Galarneau <jeremie.galarneau@efficios.com> |
| 3 | Date: Tue, 17 Jan 2023 16:57:35 -0500 |
| 4 | Subject: [PATCH] compat: off64_t is not defined by musl |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 5 | |
Andrew Geissler | c5535c9 | 2023-01-27 16:10:19 -0600 | [diff] [blame] | 6 | This helps compile with latest musl, where off64_t is not defined unless |
| 7 | _LARGEFILE64_SOURCE is defined. On glibc, _LARGEFILE64_SOURCE is defined |
| 8 | if _GNU_SOURCE is defined, so the problem is only seen with musl. |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 9 | |
Andrew Geissler | c5535c9 | 2023-01-27 16:10:19 -0600 | [diff] [blame] | 10 | Since the project uses AC_SYS_LARGEFILE, which from the autoconf doc: |
| 11 | "arrange for 64-bit file offsets, known as large-file support." |
| 12 | |
| 13 | As such, it is safe to assume off_t is 64-bit wide. This is checked by a |
| 14 | static_assert to catch any platform where autoconf would let a 32-bit |
| 15 | off_t slip. |
| 16 | |
| 17 | Upstream-Status: Submitted [https://review.lttng.org/c/lttng-tools/+/9268] |
| 18 | Reported-by: Khem Raj <raj.khem@gmail.com> |
| 19 | Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com> |
| 20 | Change-Id: If2c6007a8c85bc3f3065002af8a7538b882fb4a8 |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 21 | --- |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 22 | |
Andrew Geissler | c5535c9 | 2023-01-27 16:10:19 -0600 | [diff] [blame] | 23 | --- a/src/common/compat/compat-fcntl.c |
| 24 | +++ b/src/common/compat/compat-fcntl.c |
Patrick Williams | 864cc43 | 2023-02-09 14:54:44 -0600 | [diff] [blame^] | 25 | @@ -8,14 +8,17 @@ |
| 26 | #define _LGPL_SOURCE |
| 27 | #include <common/compat/fcntl.h> |
| 28 | #include <common/macros.h> |
| 29 | +#include <common/bug.h> |
| 30 | +#include <stdint.h> |
| 31 | #include <unistd.h> |
| 32 | |
Andrew Geissler | c5535c9 | 2023-01-27 16:10:19 -0600 | [diff] [blame] | 33 | #ifdef __linux__ |
| 34 | |
| 35 | LTTNG_HIDDEN |
| 36 | -int compat_sync_file_range(int fd, off64_t offset, off64_t nbytes, |
| 37 | +int compat_sync_file_range(int fd, off_t offset, off_t nbytes, |
| 38 | unsigned int flags) |
| 39 | { |
Patrick Williams | 864cc43 | 2023-02-09 14:54:44 -0600 | [diff] [blame^] | 40 | + LTTNG_BUILD_BUG_ON(sizeof(off_t) != sizeof(int64_t)); |
Andrew Geissler | c5535c9 | 2023-01-27 16:10:19 -0600 | [diff] [blame] | 41 | #ifdef HAVE_SYNC_FILE_RANGE |
Patrick Williams | 864cc43 | 2023-02-09 14:54:44 -0600 | [diff] [blame^] | 42 | return sync_file_range(fd, offset, nbytes, flags); |
| 43 | #else |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 44 | --- a/src/common/compat/fcntl.h |
| 45 | +++ b/src/common/compat/fcntl.h |
Patrick Williams | 864cc43 | 2023-02-09 14:54:44 -0600 | [diff] [blame^] | 46 | @@ -13,16 +13,12 @@ |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 47 | |
Andrew Geissler | c5535c9 | 2023-01-27 16:10:19 -0600 | [diff] [blame] | 48 | #include <common/compat/errno.h> |
| 49 | |
| 50 | -#if (defined(__CYGWIN__)) |
| 51 | -typedef long long off64_t; |
| 52 | -#endif |
Patrick Williams | 864cc43 | 2023-02-09 14:54:44 -0600 | [diff] [blame^] | 53 | - |
Andrew Geissler | c5535c9 | 2023-01-27 16:10:19 -0600 | [diff] [blame] | 54 | #if (defined(__FreeBSD__) || defined(__sun__)) |
| 55 | typedef off64_t loff_t; |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 56 | #endif |
| 57 | |
| 58 | #ifdef __linux__ |
Andrew Geissler | c5535c9 | 2023-01-27 16:10:19 -0600 | [diff] [blame] | 59 | -extern int compat_sync_file_range(int fd, off64_t offset, off64_t nbytes, |
| 60 | +extern int compat_sync_file_range(int fd, off_t offset, off_t nbytes, |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 61 | unsigned int flags); |
| 62 | #define lttng_sync_file_range(fd, offset, nbytes, flags) \ |
Andrew Geissler | c5535c9 | 2023-01-27 16:10:19 -0600 | [diff] [blame] | 63 | compat_sync_file_range(fd, offset, nbytes, flags) |
Patrick Williams | 864cc43 | 2023-02-09 14:54:44 -0600 | [diff] [blame^] | 64 | @@ -37,8 +33,8 @@ extern int compat_sync_file_range(int fd |
Andrew Geissler | c5535c9 | 2023-01-27 16:10:19 -0600 | [diff] [blame] | 65 | #define SYNC_FILE_RANGE_WAIT_BEFORE 0 |
| 66 | #define SYNC_FILE_RANGE_WRITE 0 |
| 67 | |
| 68 | -static inline int lttng_sync_file_range(int fd, off64_t offset, |
| 69 | - off64_t nbytes, unsigned int flags) |
| 70 | +static inline int lttng_sync_file_range(int fd, off_t offset, |
| 71 | + off_t nbytes, unsigned int flags) |
| 72 | { |
| 73 | return -ENOSYS; |
| 74 | } |