socket_wrapper: inject O_LARGEFILE to open[64|at]() if needed
authorStefan Metzmacher <metze@samba.org>
Wed, 23 Nov 2022 10:46:45 +0000 (11:46 +0100)
committerAndreas Schneider <asn@samba.org>
Thu, 24 Nov 2022 09:24:11 +0000 (10:24 +0100)
On 32bit systems this is normally done by glibc if _FILE_OFFSET_BITS is 64,
but with socket wrapper we don't want to define _FILE_OFFSET_BITS=64,
as we need to overload open64 explicitly. But we need to inject
O_LARGEFILE for being transparent to the application.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=15251

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
src/socket_wrapper.c

index aefd526ddfe633f4e158138534a0d0b8d6ea3095..bedda07a72b939cb8a302b40bca174d048925009 100644 (file)
@@ -984,6 +984,19 @@ static FILE *libc_fopen64(const char *name, const char *mode)
 }
 #endif /* HAVE_FOPEN64 */
 
+static void swrap_inject_o_largefile(int *flags)
+{
+       (void)*flags; /* maybe unused */
+#if SIZE_MAX == 0xffffffffUL && defined(O_LARGEFILE)
+#ifdef O_PATH
+       if (((*flags) & O_PATH) == 0)
+#endif
+       {
+               *flags |= O_LARGEFILE;
+       }
+#endif
+}
+
 static int libc_vopen(const char *pathname, int flags, va_list ap)
 {
        int mode = 0;
@@ -991,6 +1004,8 @@ static int libc_vopen(const char *pathname, int flags, va_list ap)
 
        swrap_bind_symbol_all();
 
+       swrap_inject_o_largefile(&flags);
+
        if (flags & O_CREAT) {
                mode = va_arg(ap, int);
        }
@@ -1019,6 +1034,8 @@ static int libc_vopen64(const char *pathname, int flags, va_list ap)
 
        swrap_bind_symbol_all();
 
+       swrap_inject_o_largefile(&flags);
+
        if (flags & O_CREAT) {
                mode = va_arg(ap, int);
        }
@@ -1035,6 +1052,8 @@ static int libc_vopenat(int dirfd, const char *path, int flags, va_list ap)
 
        swrap_bind_symbol_all();
 
+       swrap_inject_o_largefile(&flags);
+
        if (flags & O_CREAT) {
                mode = va_arg(ap, int);
        }