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)
181 return XrdPosix_Open(path, O_WRONLY | O_CREAT | O_TRUNC, mode);
192int fcntl(
int fd,
int cmd, ...)
200 theArg = va_arg(ap,
void *);
229int fseeko(FILE *stream, off_t offset,
int whence)
242#if !defined(SUNX86) && !defined(__FreeBSD__)
245#if defined __linux__ && __GNUC__ && __GNUC__ >= 2
246int __fxstat(
int ver,
int fildes,
struct stat *buf)
247#elif defined(__solaris__) && defined(__i386)
248int _fxstat(
int ver,
int fildes,
struct stat *buf)
255#if defined(__linux__) and defined(_STAT_VER)
261#if defined(__LP64__) || defined(_LP64)
267 return XrdPosix_CopyStat(buf, buf64);
294#if !defined(SUNX86) && !defined(__FreeBSD__)
310#if !defined(SUNX86) && !defined(__FreeBSD__)
313off_t
lseek(
int fildes, off_t offset,
int whence)
326#if !defined(SUNX86) && !defined(__FreeBSD__)
329#if defined __GNUC__ && __GNUC__ >= 2 && defined(__linux__)
330int __lxstat(
int ver,
const char *path,
struct stat *buf)
331#elif defined(__solaris__) && defined(__i386)
332int _lxstat(
int ver,
const char *path,
struct stat *buf)
334int lstat(
const char *path,
struct stat *buf)
340#if defined(__linux__) and defined(_STAT_VER)
346#if defined(__LP64__) || defined(_LP64)
353 return XrdPosix_CopyStat(buf, buf64);
363#if !defined(SUNX86) && !defined(__FreeBSD__)
366int open(
const char *path,
int oflag, ...)
373 mode = va_arg(ap,
int);
384#if !defined(SUNX86) && !defined(__FreeBSD__)
387ssize_t
pread(
int fildes,
void *buf,
size_t nbyte, off_t offset)
400#if !defined(SUNX86) && !defined(__FreeBSD__)
403struct dirent*
readdir(DIR *dirp)
406 struct dirent64 *dp64;
415#if !defined(__APPLE__) && !defined(_LP64) && !defined(__LP64__) && !(defined(__FreeBSD_kernel__) && defined(__GLIBC__))
416 if (XrdPosix_CopyDirent((
struct dirent *)dp64, dp64))
return 0;
419 return (
struct dirent *)dp64;
428#if !defined(SUNX86) && !defined(__FreeBSD__)
431int readdir_r(DIR *dirp,
struct dirent *entry,
struct dirent **result)
434#if defined(__APPLE__) || defined(__LP64__) || defined(_LP64) || (defined(__FreeBSD_kernel__) && defined(__GLIBC__))
437 char buff[
sizeof(
struct dirent64) + 2048];
438 struct dirent64 *dp64 = (
struct dirent64 *)buff;
439 struct dirent64 *mydirent;
449 if (!mydirent) {*result = 0;
return 0;}
451 if ((rc = XrdPosix_CopyDirent(entry, dp64)))
return rc;
464#if !defined(SUNX86) && !defined(__FreeBSD__)
467ssize_t
pwrite(
int fildes,
const void *buf,
size_t nbyte, off_t offset)
480#if !defined(SUNX86) && !defined(__FreeBSD__)
483#if defined __GNUC__ && __GNUC__ >= 2
484int __xstat(
int ver,
const char *path,
struct stat *buf)
485#elif defined(__solaris__) && defined(__i386)
486int _xstat(
int ver,
const char *path,
struct stat *buf)
488int stat(
const char *path,
struct stat *buf)
500#if defined(__LP64__) || defined(_LP64)
506 return XrdPosix_CopyStat(buf, buf64);
516#if !defined(__solaris__) && !defined(__APPLE__) && !defined(__FreeBSD__)
526 memset(buf, 0,
sizeof(
struct statfs));
527 buf->f_type = buf64.f_type;
528 buf->f_bsize = buf64.f_bsize;
529 buf->f_blocks = buf64.f_blocks;
530 buf->f_bfree = buf64.f_bfree;
531 buf->f_files = buf64.f_files;
532 buf->f_ffree = buf64.f_ffree;
533 buf->f_fsid = buf64.f_fsid;
534#if defined(__FreeBSD_kernel__) && defined(__GLIBC__)
535 buf->f_namemax = buf64.f_namemax;
537 buf->f_namelen = buf64.f_namelen;
548#if !defined(__APPLE__) && !defined(SUNX86) && !defined(__FreeBSD__)
557 memset(buf, 0,
sizeof(
struct statvfs));
558 buf->f_flag = buf64.f_flag;
559 buf->f_bsize = buf64.f_bsize;
560 buf->f_blocks = buf64.f_blocks;
561 buf->f_bfree = buf64.f_bfree;
562 buf->f_files = buf64.f_files;
563 buf->f_ffree = buf64.f_ffree;
564 buf->f_fsid = buf64.f_fsid;
565 buf->f_namemax = buf64.f_namemax;
575#if !defined(SUNX86) && !defined(__FreeBSD__)
578int 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_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 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)