31 #if defined(__clang__) && defined(_FORTIFY_SOURCE)
32 #undef _FORTIFY_SOURCE
36 #ifdef _LARGEFILE_SOURCE
37 #undef _LARGEFILE_SOURCE
40 #ifdef _LARGEFILE64_SOURCE
41 #undef _LARGEFILE64_SOURCE
44 #ifdef _FILE_OFFSET_BITS
45 #undef _FILE_OFFSET_BITS
53 #define XRDPOSIXPRELOAD32
60 #include <sys/types.h>
64 #if defined(__APPLE__) || defined(__FreeBSD__)
65 #include <sys/param.h>
66 #include <sys/mount.h>
68 #include <sys/statfs.h>
84 namespace {
bool isLite = (getenv(
"XRD_POSIX_PRELOAD_LITE") != 0);}
97 #if !defined(__LP64__) && !defined(_LP64)
98 #if !defined(__APPLE__) && !defined(SUNX86) && !defined(__FreeBSD__) && !(defined(__FreeBSD_kernel__) && defined(__GLIBC__))
101 const unsigned long long LLMask = 0xffffffff00000000LL;
102 int isdiff = (dent->d_name-(
char *)dent) != (dent64->d_name-(
char *)dent64);
105 if (isdiff && (dent64->d_ino & LLMask))
107 if (isdiff && ((dent64->d_ino & LLMask) || (dent64->d_off & LLMask)))
109 {errno = EOVERFLOW;
return EOVERFLOW;}
111 if (isdiff || (
void *)dent != (
void *)dent64)
112 {dent->d_ino = dent64->d_ino;
113 #if !defined(__GNU__)
114 dent->d_off = dent64->d_off;
116 dent->d_reclen = dent64->d_reclen;
117 dent->d_type = dent64->d_type;
119 dent->d_namlen = dent64->d_namlen;
121 strcpy(dent->d_name, dent64->d_name);
138 #if !defined(__LP64__) && !defined(_LP64)
139 #if !defined(SUNX86) && !defined(__FreeBSD__)
142 const unsigned long long LLMask = 0xffffffff00000000LL;
143 const int INTMax = 0x7fffffff;
145 if (buf64.st_size & LLMask)
146 if (buf64.st_mode & S_IFREG || buf64.st_mode & S_IFDIR)
147 {errno = EOVERFLOW;
return -1;}
148 else buf->st_size = INTMax;
149 else buf->st_size = buf64.st_size;
151 buf->st_ino = buf64.st_ino & LLMask ? INTMax : buf64.st_ino;
152 buf->st_blocks= buf64.st_blocks & LLMask ? INTMax : buf64.st_blocks;
153 buf->st_mode = buf64.st_mode;
154 buf->st_dev = buf64.st_dev;
155 buf->st_rdev = buf64.st_rdev;
156 buf->st_nlink = buf64.st_nlink;
157 buf->st_uid = buf64.st_uid;
158 buf->st_gid = buf64.st_gid;
159 buf->st_atime = buf64.st_atime;
160 buf->st_mtime = buf64.st_mtime;
161 buf->st_ctime = buf64.st_ctime;
162 buf->st_blksize=buf64.st_blksize;
172 #if !defined(SUNX86) && !defined(__FreeBSD__)
175 int creat(
const char *path, mode_t mode)
179 return XrdPosix_Open(path, O_WRONLY | O_CREAT | O_TRUNC, mode);
198 theArg = va_arg(ap,
void *);
227 int fseeko(FILE *stream, off_t offset,
int whence)
240 #if !defined(SUNX86) && !defined(__FreeBSD__)
243 #if defined __linux__ && __GNUC__ && __GNUC__ >= 2
244 int __fxstat(
int ver,
int fildes,
struct stat *buf)
245 #elif defined(__solaris__) && defined(__i386)
246 int _fxstat(
int ver,
int fildes,
struct stat *buf)
253 #if defined(__linux__) and defined(_STAT_VER)
259 #if defined(__LP64__) || defined(_LP64)
292 #if !defined(SUNX86) && !defined(__FreeBSD__)
308 #if !defined(SUNX86) && !defined(__FreeBSD__)
311 off_t
lseek(
int fildes, off_t offset,
int whence)
324 #if !defined(SUNX86) && !defined(__FreeBSD__)
327 #if defined __GNUC__ && __GNUC__ >= 2 && defined(__linux__)
328 int __lxstat(
int ver,
const char *path,
struct stat *buf)
329 #elif defined(__solaris__) && defined(__i386)
330 int _lxstat(
int ver,
const char *path,
struct stat *buf)
338 #if defined(__linux__) and defined(_STAT_VER)
344 #if defined(__LP64__) || defined(_LP64)
361 #if !defined(SUNX86) && !defined(__FreeBSD__)
364 int open(
const char *path,
int oflag, ...)
371 mode = va_arg(ap,
int);
382 #if !defined(SUNX86) && !defined(__FreeBSD__)
385 ssize_t
pread(
int fildes,
void *buf,
size_t nbyte, off_t offset)
398 #if !defined(SUNX86) && !defined(__FreeBSD__)
404 struct dirent64 *dp64;
413 #if !defined(__APPLE__) && !defined(_LP64) && !defined(__LP64__) && !(defined(__FreeBSD_kernel__) && defined(__GLIBC__))
417 return (
struct dirent *)dp64;
426 #if !defined(SUNX86) && !defined(__FreeBSD__)
429 int readdir_r(DIR *dirp,
struct dirent *entry,
struct dirent **result)
432 #if defined(__APPLE__) || defined(__LP64__) || defined(_LP64) || (defined(__FreeBSD_kernel__) && defined(__GLIBC__))
435 char buff[
sizeof(
struct dirent64) + 2048];
436 struct dirent64 *dp64 = (
struct dirent64 *)buff;
437 struct dirent64 *mydirent;
447 if (!mydirent) {*result = 0;
return 0;}
462 #if !defined(SUNX86) && !defined(__FreeBSD__)
465 ssize_t
pwrite(
int fildes,
const void *buf,
size_t nbyte, off_t offset)
478 #if !defined(SUNX86) && !defined(__FreeBSD__)
481 #if defined __GNUC__ && __GNUC__ >= 2
482 int __xstat(
int ver,
const char *path,
struct stat *buf)
483 #elif defined(__solaris__) && defined(__i386)
484 int _xstat(
int ver,
const char *path,
struct stat *buf)
498 #if defined(__LP64__) || defined(_LP64)
514 #if !defined(__solaris__) && !defined(__APPLE__) && !defined(__FreeBSD__)
524 memset(buf, 0,
sizeof(
struct statfs));
525 buf->f_type = buf64.f_type;
526 buf->f_bsize = buf64.f_bsize;
527 buf->f_blocks = buf64.f_blocks;
528 buf->f_bfree = buf64.f_bfree;
529 buf->f_files = buf64.f_files;
530 buf->f_ffree = buf64.f_ffree;
531 buf->f_fsid = buf64.f_fsid;
532 #if defined(__FreeBSD_kernel__) && defined(__GLIBC__)
533 buf->f_namemax = buf64.f_namemax;
535 buf->f_namelen = buf64.f_namelen;
546 #if !defined(__APPLE__) && !defined(SUNX86) && !defined(__FreeBSD__)
555 memset(buf, 0,
sizeof(
struct statvfs));
556 buf->f_flag = buf64.f_flag;
557 buf->f_bsize = buf64.f_bsize;
558 buf->f_blocks = buf64.f_blocks;
559 buf->f_bfree = buf64.f_bfree;
560 buf->f_files = buf64.f_files;
561 buf->f_ffree = buf64.f_ffree;
562 buf->f_fsid = buf64.f_fsid;
563 buf->f_namemax = buf64.f_namemax;
573 #if !defined(SUNX86) && !defined(__FreeBSD__)
int truncate(const char *path, off_t offset)
ssize_t pwrite(int fildes, const void *buf, size_t nbyte, off_t offset)
int readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result)
int XrdPosix_CopyDirent(struct dirent *dent, struct dirent64 *dent64)
off_t lseek(int fildes, off_t offset, int whence)
int stat(const char *path, struct stat *buf)
int XrdPosix_CopyStat(struct stat *buf, struct stat64 &buf64)
int ftruncate(int fildes, off_t offset)
struct dirent * readdir(DIR *dirp)
int open(const char *path, int oflag,...)
ssize_t pread(int fildes, void *buf, size_t nbyte, off_t offset)
off_t ftello(FILE *stream)
int fseeko(FILE *stream, off_t offset, int whence)
int fstat(int fildes, struct stat *buf)
int lstat(const char *path, struct stat *buf)
int fcntl(int fd, int cmd,...)
int statvfs(const char *path, struct statvfs *buf)
int statfs(const char *path, struct statfs *buf)
int creat(const char *path, mode_t mode)
int statvfs64(const char *path, struct statvfs64 *buf)
int statfs64(const char *path, struct statfs64 *buf)
int stat64(const char *path, struct stat64 *buf)
int XrdPosix_Statfs(const char *path, struct statfs *buf)
long long XrdPosix_Pread(int fildes, void *buf, unsigned long long nbyte, long long offset)
long long XrdPosix_Lseek(int fildes, long long offset, int whence)
int XrdPosix_isMyPath(const char *path)
long long XrdPosix_Ftello(FILE *stream)
int XrdPosix_Open(const char *path, int oflag,...)
int XrdPosix_Readdir64_r(DIR *dirp, struct dirent64 *entry, struct dirent64 **result)
int XrdPosix_Stat(const char *path, struct stat *buf)
int XrdPosix_Readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result)
long long XrdPosix_Pwrite(int fildes, const void *buf, unsigned long long nbyte, long long offset)
int XrdPosix_Lstat(const char *path, struct stat *buf)
int XrdPosix_Statvfs(const char *path, struct statvfs *buf)
int XrdPosix_Fstat(int fildes, struct stat *buf)
int XrdPosix_Ftruncate(int fildes, long long offset)
struct dirent64 * XrdPosix_Readdir64(DIR *dirp)
int XrdPosix_Truncate(const char *path, long long offset)
int XrdPosix_Fseeko(FILE *stream, long long offset, int whence)
Retv_Fcntl(* Fcntl)(Args_Fcntl)
Retv_Readdir64(* Readdir64)(Args_Readdir64)
Retv_Stat(* Stat)(Args_Stat)
Retv_Readdir64_r(* Readdir64_r)(Args_Readdir64_r)
Retv_Lstat(* Lstat)(Args_Lstat)
Retv_Fstat(* Fstat)(Args_Fstat)