]> xenbits.xensource.com Git - libvirt.git/commitdiff
virmockstathelpers: Load aliases for 64-bit time
authorMichal Privoznik <mprivozn@redhat.com>
Fri, 18 Nov 2022 16:13:22 +0000 (17:13 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Mon, 21 Nov 2022 14:49:36 +0000 (15:49 +0100)
On 32-bit arches, it's possible not only to request
-D_FILE_OFFSET_BITS=64 (which is always done with meson) but also
-D_TIME_BITS=64. With glibc, both of these affect what variant of
stat() or lstat() is called. With 64 bit time it's:
__stat64_time64() or __lstat64_time64(), respectively.

Fortunately, no other variant (__xstat(), __xstat64()) has
_time64 alternative and thus does not need similar treatment.

Similarly, musl is not affected by this.

Resolves: https://gitlab.com/libvirt/libvirt/-/issues/404
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
tests/virmockstathelpers.c

index 39e270eaac28f9538ac9d1be7e7d6b6404fff3f8..5b1f3b08a7c2244cba9a6e806780efc62a96494e 100644 (file)
  * Unfortunately, because we are trying to mock replace the C library,
  * we need to know about this internal impl detail.
  *
+ * Furthermore, support for 64-bit time can be enabled, which on 32-bit
+ * systems with glibc overwrites stat64() to __stat64_time64() and lstat64()
+ * to __lstat64_time64().
+ *
  * On macOS stat() and lstat() are resolved to _stat$INODE64 and
  * _lstat$INODE64, respectively. stat(2) man page also declares that
  * stat64(), lstat64() and fstat64() are deprecated, and when
@@ -168,7 +172,11 @@ static void virMockStatInit(void)
     fdebug("real stat %p\n", real_stat);
 #endif
 #ifdef MOCK_STAT64
+# if defined(__GLIBC__) && defined(_TIME_BITS) && _TIME_BITS == 64
+    VIR_MOCK_REAL_INIT_ALIASED(stat64, "__stat64_time64");
+# else
     VIR_MOCK_REAL_INIT(stat64);
+# endif
     fdebug("real stat64 %p\n", real_stat64);
 #endif
 #ifdef MOCK___XSTAT
@@ -188,7 +196,11 @@ static void virMockStatInit(void)
     fdebug("real lstat %p\n", real_lstat);
 #endif
 #ifdef MOCK_LSTAT64
+# if defined(__GLIBC__) && defined(_TIME_BITS) && _TIME_BITS == 64
+    VIR_MOCK_REAL_INIT_ALIASED(lstat64, "__lstat64_time64");
+# else
     VIR_MOCK_REAL_INIT(lstat64);
+# endif
     fdebug("real lstat64 %p\n", real_lstat64);
 #endif
 #ifdef MOCK___LXSTAT