| 1 |
// Compatibility shims for cross-platform compilation |
| 2 |
// This header provides compatibility macros for different libc implementations |
| 3 |
|
| 4 |
#ifndef COMPAT_H |
| 5 |
#define COMPAT_H |
| 6 |
|
| 7 |
// Detect musl libc |
| 8 |
// Musl doesn't define a specific macro, but we can detect it by checking for |
| 9 |
// the absence of __GLIBC__ on Linux systems, or by checking features.h |
| 10 |
#if defined(__linux__) && !defined(__GLIBC__) && !defined(__BIONIC__) |
| 11 |
#define COMPAT_MUSL 1 |
| 12 |
#endif |
| 13 |
|
| 14 |
// Musl libc compatibility |
| 15 |
// Musl doesn't have separate *64 functions because all functions are 64-bit |
| 16 |
// clean. Map the glibc LFS64 (Large File Support) functions to their standard |
| 17 |
// equivalents. |
| 18 |
#if defined(COMPAT_MUSL) |
| 19 |
#define openat64 openat |
| 20 |
#define fopen64 fopen |
| 21 |
#define freopen64 freopen |
| 22 |
#define lseek64 lseek |
| 23 |
#define fseeko64 fseeko |
| 24 |
#define ftello64 ftello |
| 25 |
#define fgetpos64 fgetpos |
| 26 |
#define fsetpos64 fsetpos |
| 27 |
#define stat64 stat |
| 28 |
#define fstat64 fstat |
| 29 |
#define lstat64 lstat |
| 30 |
#define fstatat64 fstatat |
| 31 |
#define mmap64 mmap |
| 32 |
#define off64_t off_t |
| 33 |
#define ino64_t ino_t |
| 34 |
#endif |
| 35 |
|
| 36 |
#endif // COMPAT_H |