31#if defined(__clang__) && defined(_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
66#if defined(__APPLE__) || defined(__FreeBSD__)
70#include <sys/statfs.h>
86namespace {
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__))
101int 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;
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__)
142int 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__)
177int creat(
const char *path, mode_t mode)
179 static int Init =
Xunix.Init(&Init);
181 return XrdPosix_Open(path, O_WRONLY | O_CREAT | O_TRUNC, mode);
192int fcntl(
int fd,
int cmd, ...)
194 static int Init =
Xunix.Init(&Init);
200 theArg = va_arg(ap,
void *);
202 return Xunix.Fcntl(fd, cmd, theArg);
229int fseeko(FILE *stream, off_t offset,
int whence)
231 static int Init =
Xunix.Init(&Init);
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)
252 static int Init =
Xunix.Init(&Init);
254#if defined(__linux__) && defined(_STAT_VER) && __GNUC__ && __GNUC__ >= 2
261#if defined(__LP64__) || defined(_LP64)
267 return XrdPosix_CopyStat(buf, buf64);
279 static int Init =
Xunix.Init(&Init);
280#if defined(__LP64__) || defined(_LP64)
286 return XrdPosix_CopyStat(buf, buf64);
301 static int Init =
Xunix.Init(&Init);
312#if !defined(SUNX86) && !defined(__FreeBSD__)
317 static int Init =
Xunix.Init(&Init);
328#if !defined(SUNX86) && !defined(__FreeBSD__)
331off_t
lseek(
int fildes, off_t offset,
int whence)
333 static int Init =
Xunix.Init(&Init);
344#if !defined(SUNX86) && !defined(__FreeBSD__)
347#if defined __GNUC__ && defined(_STAT_VER) && __GNUC__ >= 2 && defined(__linux__)
348int __lxstat(
int ver,
const char *path,
struct stat *buf)
349#elif defined(__solaris__) && defined(__i386)
350int _lxstat(
int ver,
const char *path,
struct stat *buf)
352int lstat(
const char *path,
struct stat *buf)
355 static int Init =
Xunix.Init(&Init);
357#if defined(__linux__) and defined(_STAT_VER)
359 return Xunix.Lstat(ver, path, buf);
363 return Xunix.Lstat( path, buf);
366#if defined(__LP64__) || defined(_LP64)
373 return XrdPosix_CopyStat(buf, buf64);
383#if !defined(SUNX86) && !defined(__FreeBSD__)
386int open(
const char *path,
int oflag, ...)
388 static int Init =
Xunix.Init(&Init);
393 mode = va_arg(ap,
int);
404#if !defined(SUNX86) && !defined(__FreeBSD__)
407ssize_t
pread(
int fildes,
void *buf,
size_t nbyte, off_t offset)
409 static int Init =
Xunix.Init(&Init);
420#if !defined(SUNX86) && !defined(__FreeBSD__)
423struct dirent*
readdir(DIR *dirp)
425 static int Init =
Xunix.Init(&Init);
426 struct dirent64 *dp64;
430 if (!(dp64 =
Xunix.Readdir64(dirp)))
return 0;
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__)
451int readdir_r(DIR *dirp,
struct dirent *entry,
struct dirent **result)
453 static int Init =
Xunix.Init(&Init);
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;
464 if ((rc =
Xunix.Readdir64_r(dirp, dp64, &mydirent)))
return rc;
469 if (!mydirent) {*result = 0;
return 0;}
471 if ((rc = XrdPosix_CopyDirent(entry, dp64)))
return rc;
484#if !defined(SUNX86) && !defined(__FreeBSD__)
487ssize_t
pwrite(
int fildes,
const void *buf,
size_t nbyte, off_t offset)
489 static int Init =
Xunix.Init(&Init);
500#if !defined(SUNX86) && !defined(__FreeBSD__)
503#if defined __linux__ && defined(_STAT_VER) && defined __GNUC__ && __GNUC__ >= 2
504int __xstat(
int ver,
const char *path,
struct stat *buf)
505#elif defined(__solaris__) && defined(__i386)
506int _xstat(
int ver,
const char *path,
struct stat *buf)
508int stat(
const char *path,
struct stat *buf)
511 static int Init =
Xunix.Init(&Init);
512#if defined( __linux__) && defined(_STAT_VER)
514 return Xunix.Stat(ver, path, buf);
518 return Xunix.Stat( path, buf);
521#if defined(__LP64__) || defined(_LP64)
527 return XrdPosix_CopyStat(buf, buf64);
537#if !defined(__solaris__) && !defined(__APPLE__) && !defined(__FreeBSD__)
542 static int Init =
Xunix.Init(&Init);
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__)
574 static int Init =
Xunix.Init(&Init);
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__)
599int truncate(
const char *path, off_t offset)
601 static int Init =
Xunix.Init(&Init);
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)