31 #if defined(__clang__) && defined(_FORTIFY_SOURCE)
32 #undef _FORTIFY_SOURCE
35 #if defined(__LP64__) || defined(_LP64)
38 #ifdef _LARGEFILE_SOURCE
39 #undef _LARGEFILE_SOURCE
42 #ifdef _LARGEFILE64_SOURCE
43 #undef _LARGEFILE64_SOURCE
46 #ifdef _FILE_OFFSET_BITS
47 #undef _FILE_OFFSET_BITS
55 #define XRDPOSIXPRELOAD32
62 #include <sys/types.h>
66 #if defined(__APPLE__) || defined(__FreeBSD__)
67 #include <sys/param.h>
68 #include <sys/mount.h>
70 #include <sys/statfs.h>
86 namespace {
bool isLite = (getenv(
"XRD_POSIX_PRELOAD_LITE") != 0);}
99 #if !defined(__LP64__) && !defined(_LP64)
100 #if !defined(__APPLE__) && !defined(SUNX86) && !defined(__FreeBSD__) && !(defined(__FreeBSD_kernel__) && defined(__GLIBC__))
101 int XrdPosix_CopyDirent(
struct dirent *dent,
struct dirent64 *dent64)
103 const unsigned long long LLMask = 0xffffffff00000000LL;
104 int isdiff = (dent->d_name-(
char *)dent) != (dent64->d_name-(
char *)dent64);
107 if (isdiff && (dent64->d_ino & LLMask))
109 if (isdiff && ((dent64->d_ino & LLMask) || (dent64->d_off & LLMask)))
111 {errno = EOVERFLOW;
return EOVERFLOW;}
113 if (isdiff || (
void *)dent != (
void *)dent64)
114 {dent->d_ino = dent64->d_ino;
115 #if !defined(__GNU__)
116 dent->d_off = dent64->d_off;
118 dent->d_reclen = dent64->d_reclen;
119 dent->d_type = dent64->d_type;
121 dent->d_namlen = dent64->d_namlen;
123 strcpy(dent->d_name, dent64->d_name);
140 #if !defined(__LP64__) && !defined(_LP64)
141 #if !defined(SUNX86) && !defined(__FreeBSD__)
142 int XrdPosix_CopyStat(
struct stat *buf,
struct stat64 &buf64)
144 const unsigned long long LLMask = 0xffffffff00000000LL;
145 const int INTMax = 0x7fffffff;
147 if (buf64.st_size & LLMask)
148 if (buf64.st_mode & S_IFREG || buf64.st_mode & S_IFDIR)
149 {errno = EOVERFLOW;
return -1;}
150 else buf->st_size = INTMax;
151 else buf->st_size = buf64.st_size;
153 buf->st_ino = buf64.st_ino & LLMask ? INTMax : buf64.st_ino;
154 buf->st_blocks= buf64.st_blocks & LLMask ? INTMax : buf64.st_blocks;
155 buf->st_mode = buf64.st_mode;
156 buf->st_dev = buf64.st_dev;
157 buf->st_rdev = buf64.st_rdev;
158 buf->st_nlink = buf64.st_nlink;
159 buf->st_uid = buf64.st_uid;
160 buf->st_gid = buf64.st_gid;
161 buf->st_atime = buf64.st_atime;
162 buf->st_mtime = buf64.st_mtime;
163 buf->st_ctime = buf64.st_ctime;
164 buf->st_blksize=buf64.st_blksize;
174 #if !defined(SUNX86) && !defined(__FreeBSD__)
177 int creat(
const char *path, mode_t mode)
181 return XrdPosix_Open(path, O_WRONLY | O_CREAT | O_TRUNC, mode);
192 int fcntl(
int fd,
int cmd, ...)
200 theArg = va_arg(ap,
void *);
229 int fseeko(FILE *stream, off_t offset,
int whence)
244 #if defined(__linux__) && defined(_STAT_VER) && __GNUC__ && __GNUC__ >= 2
245 int __fxstat(
int ver,
int fildes,
struct stat *buf)
246 #elif defined(__solaris__) && defined(__i386)
247 int _fxstat(
int ver,
int fildes,
struct stat *buf)
254 #if defined(__linux__) && defined(_STAT_VER) && __GNUC__ && __GNUC__ >= 2
261 #if defined(__LP64__) || defined(_LP64)
267 return XrdPosix_CopyStat(buf, buf64);
280 #if defined(__LP64__) || defined(_LP64)
286 return XrdPosix_CopyStat(buf, buf64);
299 off_t
ftello(FILE *stream)
312 #if !defined(SUNX86) && !defined(__FreeBSD__)
328 #if !defined(SUNX86) && !defined(__FreeBSD__)
331 off_t
lseek(
int fildes, off_t offset,
int whence)
344 #if !defined(SUNX86) && !defined(__FreeBSD__)
347 #if defined __GNUC__ && defined(_STAT_VER) && __GNUC__ >= 2 && defined(__linux__)
348 int __lxstat(
int ver,
const char *path,
struct stat *buf)
349 #elif defined(__solaris__) && defined(__i386)
350 int _lxstat(
int ver,
const char *path,
struct stat *buf)
352 int lstat(
const char *path,
struct stat *buf)
357 #if defined(__linux__) and defined(_STAT_VER)
366 #if defined(__LP64__) || defined(_LP64)
373 return XrdPosix_CopyStat(buf, buf64);
383 #if !defined(SUNX86) && !defined(__FreeBSD__)
386 int open(
const char *path,
int oflag, ...)
393 mode = va_arg(ap,
int);
404 #if !defined(SUNX86) && !defined(__FreeBSD__)
407 ssize_t
pread(
int fildes,
void *buf,
size_t nbyte, off_t offset)
420 #if !defined(SUNX86) && !defined(__FreeBSD__)
423 struct dirent*
readdir(DIR *dirp)
426 struct dirent64 *dp64;
435 #if !defined(__APPLE__) && !defined(_LP64) && !defined(__LP64__) && !(defined(__FreeBSD_kernel__) && defined(__GLIBC__))
436 if (XrdPosix_CopyDirent((
struct dirent *)dp64, dp64))
return 0;
439 return (
struct dirent *)dp64;
448 #if !defined(SUNX86) && !defined(__FreeBSD__)
451 int readdir_r(DIR *dirp,
struct dirent *entry,
struct dirent **result)
454 #if defined(__APPLE__) || defined(__LP64__) || defined(_LP64) || (defined(__FreeBSD_kernel__) && defined(__GLIBC__))
457 char buff[
sizeof(
struct dirent64) + 2048];
458 struct dirent64 *dp64 = (
struct dirent64 *)buff;
459 struct dirent64 *mydirent;
469 if (!mydirent) {*result = 0;
return 0;}
471 if ((rc = XrdPosix_CopyDirent(entry, dp64)))
return rc;
484 #if !defined(SUNX86) && !defined(__FreeBSD__)
487 ssize_t
pwrite(
int fildes,
const void *buf,
size_t nbyte, off_t offset)
500 #if !defined(SUNX86) && !defined(__FreeBSD__)
503 #if defined __linux__ && defined(_STAT_VER) && defined __GNUC__ && __GNUC__ >= 2
504 int __xstat(
int ver,
const char *path,
struct stat *buf)
505 #elif defined(__solaris__) && defined(__i386)
506 int _xstat(
int ver,
const char *path,
struct stat *buf)
508 int stat(
const char *path,
struct stat *buf)
512 #if defined( __linux__) && defined(_STAT_VER)
521 #if defined(__LP64__) || defined(_LP64)
527 return XrdPosix_CopyStat(buf, buf64);
537 #if !defined(__solaris__) && !defined(__APPLE__) && !defined(__FreeBSD__)
547 memset(buf, 0,
sizeof(
struct statfs));
548 buf->f_type = buf64.f_type;
549 buf->f_bsize = buf64.f_bsize;
550 buf->f_blocks = buf64.f_blocks;
551 buf->f_bfree = buf64.f_bfree;
552 buf->f_files = buf64.f_files;
553 buf->f_ffree = buf64.f_ffree;
554 buf->f_fsid = buf64.f_fsid;
555 #if defined(__FreeBSD_kernel__) && defined(__GLIBC__)
556 buf->f_namemax = buf64.f_namemax;
558 buf->f_namelen = buf64.f_namelen;
569 #if !defined(__APPLE__) && !defined(SUNX86) && !defined(__FreeBSD__)
578 memset(buf, 0,
sizeof(
struct statvfs));
579 buf->f_flag = buf64.f_flag;
580 buf->f_bsize = buf64.f_bsize;
581 buf->f_blocks = buf64.f_blocks;
582 buf->f_bfree = buf64.f_bfree;
583 buf->f_files = buf64.f_files;
584 buf->f_ffree = buf64.f_ffree;
585 buf->f_fsid = buf64.f_fsid;
586 buf->f_namemax = buf64.f_namemax;
596 #if !defined(SUNX86) && !defined(__FreeBSD__)
599 int truncate(
const char *path, off_t offset)
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)
int XrdPosix_Truncate(const char *path, off_t offset)
int XrdPosix_isMyPath(const char *path)
long long XrdPosix_Ftello(FILE *stream)
int XrdPosix_Open(const char *path, int oflag,...)
ssize_t XrdPosix_Pread(int fildes, void *buf, size_t nbyte, off_t offset)
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)
ssize_t XrdPosix_Pwrite(int fildes, const void *buf, size_t nbyte, off_t offset)
int XrdPosix_Lstat(const char *path, struct stat *buf)
int XrdPosix_Fstatat(int dirfd, const char *path, struct stat *buf, int flags)
int XrdPosix_Statvfs(const char *path, struct statvfs *buf)
int XrdPosix_Fstat(int fildes, struct stat *buf)
off_t XrdPosix_Lseek(int fildes, off_t offset, int whence)
int XrdPosix_Ftruncate(int fildes, long long offset)
struct dirent64 * XrdPosix_Readdir64(DIR *dirp)
int XrdPosix_Fseeko(FILE *stream, long long offset, int whence)
#define fstatat(a, b, c, d)
#define readdir_r(a, b, c)
#define pwrite(a, b, c, d)
#define pread(a, b, c, d)
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)