[Pkg-samba-maint] "fix" for #221618 - LARGEFILE_SOURCE in libsmbclient.h

Michael Tokarev mjt at tls.msk.ru
Sat Apr 2 16:39:06 BST 2022


I come across a "bugfix" from 11 years ago, for #221618 , which
resulted in this patch:

https://salsa.debian.org/samba-team/samba/-/blob/master/debian/patches/bug_221618_precise-64bit-prototype.patch

--- a/source3/include/libsmbclient.h
+++ b/source3/include/libsmbclient.h
@@ -81,6 +81,16 @@ extern "C" {
  #include <time.h>
  #include <utime.h>

+  /* Debian bug #221618 */
+#ifdef _LARGEFILE64_SOURCE
+#undef _LARGEFILE64_SOURCE
+#endif
+#define _LARGEFILE64_SOURCE 1
+#ifdef _FILE_OFFSET_BITS
+#undef _FILE_OFFSET_BITS
+#endif
+#define _FILE_OFFSET_BITS 64
+
  #define SMBC_BASE_FD        10000 /* smallest file descriptor returned */

  #define SMBC_WORKGROUP      1


At that time it looked dangerous already. But the thing is:
it does not actually change anything, it does not fix the
bug it was supposed to be fixed!

The thing is simple: you have to #define _LARGEFILE_SOURCE et al
*before* including common headers such as <sys/types.h> etc,
where, for example, off_t datatype is defined.  Here, at the
time this #define is processed, all common includes has already
been processed, and the off_t datatype has been defined.  We
do not change anything by #define _LARGEFILE_SOURCE here, at
all!

It is more: we actually CAN NOT fix this issue within this
very header. Because it can be included by the calling .c file
*after* it included other system includes, and sys/types.h is
already processed and types defined even before we opened
libsmbclient.h!  And second #include <sys/types.h> from
libsmbclient.h will not do anything since whole file is
obviously guarded against double-include, and the compiler
can't redefine already-defined datatypes anyway.

I wonder what can we do here.  My immediate thought is to
check if _LARGEFILE64_SOURCE is not defined or defined
"wrongly", and error out if that's the case.

Thoughts?

Thanks,

/mjt



More information about the Pkg-samba-maint mailing list