compat: off64_t is not defined by musl
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 17 Jan 2023 21:57:35 +0000 (16:57 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 22 Feb 2023 21:55:27 +0000 (16:55 -0500)
This helps compile with latest musl, where off64_t is not defined unless
_LARGEFILE64_SOURCE is defined. On glibc, _LARGEFILE64_SOURCE is defined
if _GNU_SOURCE is defined, so the problem is only seen with musl.

Since the project uses AC_SYS_LARGEFILE, which from the autoconf doc:
"arrange for 64-bit file offsets, known as large-file support."

As such, it is safe to assume off_t is 64-bit wide. This is checked by a
static_assert to catch any platform where autoconf would let a 32-bit
off_t slip.

Reported-by: Khem Raj <raj.khem@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: If2c6007a8c85bc3f3065002af8a7538b882fb4a8

src/common/compat/compat-fcntl.cpp
src/common/compat/fcntl.hpp

index f259d45774615c555daf2e213a525c19b4a57f4c..18b6fa3824cb87f672ed5eda8545149f236c6f09 100644 (file)
@@ -13,7 +13,7 @@
 
 #ifdef __linux__
 
-int compat_sync_file_range(int fd, off64_t offset, off64_t nbytes, unsigned int flags)
+int compat_sync_file_range(int fd, off_t offset, off_t nbytes, unsigned int flags)
 {
 #ifdef HAVE_SYNC_FILE_RANGE
        return sync_file_range(fd, offset, nbytes, flags);
index a526ca55d4326791e6a2177bcff51e76baf223c0..08fe02cf4c44bb97eaa5e3801d847e0284e5d6ad 100644 (file)
 
 #include <common/compat/errno.hpp>
 
-#if (defined(__CYGWIN__))
-typedef long long off64_t;
-#endif
+static_assert(sizeof(off_t) == sizeof(int64_t),
+             "Build system is misconfigured, off_t must be 64-bit wide");
 
 #if (defined(__FreeBSD__) || defined(__sun__))
 typedef off64_t loff_t;
 #endif
 
 #ifdef __linux__
-extern int compat_sync_file_range(int fd, off64_t offset, off64_t nbytes,
+extern int compat_sync_file_range(int fd, off_t offset, off_t nbytes,
                unsigned int flags);
 #define lttng_sync_file_range(fd, offset, nbytes, flags) \
        compat_sync_file_range(fd, offset, nbytes, flags)
@@ -39,8 +38,8 @@ extern int compat_sync_file_range(int fd, off64_t offset, off64_t nbytes,
 
 static inline int lttng_sync_file_range(
                int fd __attribute__((unused)),
-               off64_t offset __attribute__((unused)),
-               off64_t nbytes __attribute__((unused)),
+               off_t offset __attribute__((unused)),
+               off_t nbytes __attribute__((unused)),
                unsigned int flags __attribute__((unused)))
 {
        return -ENOSYS;
This page took 0.026815 seconds and 4 git commands to generate.