Avoid conflict with pread64/pwrite64 defined by libc

musl libc defines these to pread and pwrite respectively, since its
off_t is always 64-bit. This causes unintended macro replacement
when defining the pread64/pwrite64 wrappers.

To prevent this, save the macro definitions at the start of the
header and restore them at the end. This is what is already done
to work around the same issue on Android NDK.

Bug: linux-syscall-support:23
Change-Id: I0a91ba83fb172818a80a3584302f2c97966ec2e0
Reviewed-on: https://chromium-review.googlesource.com/c/linux-syscall-support/+/2015819
Reviewed-by: Mike Frysinger <vapier@chromium.org>
diff --git a/linux_syscall_support.h b/linux_syscall_support.h
index a71bea8..d2baee9 100644
--- a/linux_syscall_support.h
+++ b/linux_syscall_support.h
@@ -130,18 +130,23 @@
 #endif
 #endif
 
-/* The Android NDK's <sys/stat.h> #defines these macros as aliases
- * to their non-64 counterparts. To avoid naming conflict, remove them. */
-#ifdef __ANDROID__
-  /* These are restored by the corresponding #pragma pop_macro near
-   * the end of this file. */
-# pragma push_macro("stat64")
-# pragma push_macro("fstat64")
-# pragma push_macro("lstat64")
-# undef stat64
-# undef fstat64
-# undef lstat64
-#endif
+/* Some libcs, for example Android NDK and musl, #define these
+ * macros as aliases to their non-64 counterparts. To avoid naming
+ * conflict, remove them.
+ *
+ * These are restored by the corresponding #pragma pop_macro near
+ * the end of this file.
+ */
+#pragma push_macro("stat64")
+#pragma push_macro("fstat64")
+#pragma push_macro("lstat64")
+#pragma push_macro("pread64")
+#pragma push_macro("pwrite64")
+#undef stat64
+#undef fstat64
+#undef lstat64
+#undef pread64
+#undef pwrite64
 
 #if defined(__ANDROID__) && defined(__x86_64__)
 // A number of x86_64 syscalls are blocked by seccomp on recent Android;
@@ -4511,13 +4516,13 @@
 # endif
 #endif
 
-#ifdef __ANDROID__
-  /* These restore the original values of these macros saved by the
-   * corresponding #pragma push_macro near the top of this file. */
-# pragma pop_macro("stat64")
-# pragma pop_macro("fstat64")
-# pragma pop_macro("lstat64")
-#endif
+/* These restore the original values of these macros saved by the
+ * corresponding #pragma push_macro near the top of this file. */
+#pragma pop_macro("stat64")
+#pragma pop_macro("fstat64")
+#pragma pop_macro("lstat64")
+#pragma pop_macro("pread64")
+#pragma pop_macro("pwrite64")
 
 #if defined(__cplusplus) && !defined(SYS_CPLUSPLUS)
 }