69#if defined _IO_ERR_SEEN || defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1
71 fp->_flags |= _IO_ERR_SEEN;
72#elif defined __sferror || defined __APPLE__ || defined __DragonFly__ || defined __FreeBSD__ || defined __ANDROID__
78#elif defined __UCLIBC__
79 fp->__modeflags |= __FLAG_ERROR;
83 #error "Unsupported platform! Please report it as a bug."
92#if defined _IO_EOF_SEEN || defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1
94 fp->_flags |= _IO_EOF_SEEN;
95#elif defined __sferror || defined __APPLE__ || defined __DragonFly__ || defined __ANDROID__
101#elif defined __UCLIBC__
102 fp->__modeflags |= __FLAG_EOF;
104 (void)
fseek(fp, 0L, SEEK_END);
116 char *myPath, buff[2048];
120 if (!path) {errno = EFAULT;
return -1;}
124 if (!(myPath =
XrootPath.URL(path, buff,
sizeof(buff))))
125 return Xunix.Access( path, amode);
129 return Xroot.Access(myPath, amode);
141int XrdPosix_Acl(
const char *path,
int cmd,
int nentries,
void *aclbufp)
144 ?
Xunix.Acl(
"/tmp", cmd,nentries,aclbufp)
145 :
Xunix.Acl(path, cmd,nentries,aclbufp));
177 return (
Xroot.myFD(fildes) ?
Xroot.Close(fildes) :
Xunix.Close(fildes));
190 return (
Xroot.isXrootdDir(dirp) ?
Xroot.Closedir(dirp)
191 :
Xunix.Closedir(dirp));
205 return XrdPosix_Open(path, O_WRONLY | O_CREAT | O_TRUNC, mode);
217 int nullfd = fileno(stream);
225 return Xunix.Fclose(stream);
240 if (
Xroot.myFD(fd))
return 0;
242 theArg = va_arg(ap,
void *);
244 return Xunix.Fcntl64(fd, cmd, theArg);
259 return (
Xroot.myFD(fildes) ?
Xroot.Fsync(fildes)
260 :
Xunix.Fsync(fildes));
268#if defined(__linux__) || defined(__GNU__) || (defined(__FreeBSD_kernel__) && defined(__GLIBC__))
271long long XrdPosix_Fgetxattr (
int fd,
const char *name,
void *value,
272 unsigned long long size)
274 if (
Xroot.myFD(fd)) {errno = ENOTSUP;
return -1;}
275 return Xunix.Fgetxattr(fd, name, value, size);
291 if (!stream || !
Xroot.myFD(fileno(stream)))
292 return Xunix.Fflush(stream);
294 return Xroot.Fsync(fileno(stream));
302#define ISMODE(x) !strcmp(mode, x)
308 char *myPath, buff[2048];
314 if (!(myPath =
XrootPath.URL(path, buff,
sizeof(buff))))
315 return Xunix.Fopen64(path, mode);
327 else {errno = EINVAL;
return 0;}
336 if (!(stream = fdopen(fd, mode)))
337 {erc = errno;
Xroot.Close(fd); errno = erc;}
355 int fd = fileno(stream);
357 if (!
Xroot.myFD(fd))
return Xunix.Fread(ptr, size, nitems, stream);
359 bytes =
Xroot.Read(fd, ptr, size*nitems);
363 if (bytes > 0 && size) rc = bytes/size;
364 else if (bytes < 0)
fseterr(stream);
382 if (!
Xroot.myFD(fileno(stream)))
383 return Xunix.Fseek( stream, offset, whence);
385 return (
Xroot.Lseek(fileno(stream), offset, whence) < 0 ? -1 : 0);
400 if (!
Xroot.myFD(fileno(stream)))
401 return Xunix.Fseeko64(stream, offset, whence);
403 return (
Xroot.Lseek(fileno(stream), offset, whence) < 0 ? -1 : 0);
418 return (
Xroot.myFD(fildes)
419 ?
Xroot.Fstat(fildes, buf)
420#
if defined(__linux__) and defined(_STAT_VER)
421 :
Xunix.Fstat64(_STAT_VER, fildes, (
struct stat64 *)buf));
428int XrdPosix_FstatV(
int ver,
int fildes,
struct stat *buf)
430 return (
Xroot.myFD(fildes)
431 ?
Xroot.Fstat(fildes, buf)
433 :
Xunix.Fstat64(ver, fildes, (
struct stat64 *)buf));
452 return (
Xroot.myFD(fildes) ?
Xroot.Fsync(fildes)
453 :
Xunix.Fsync(fildes));
468 if (!
Xroot.myFD(fileno(stream)))
return Xunix.Ftell(stream);
470 return static_cast<long>(
Xroot.Lseek(fileno(stream), 0, SEEK_CUR));
485 if (!
Xroot.myFD(fileno(stream)))
return Xunix.Ftello64(stream);
487 return Xroot.Lseek(fileno(stream), 0, SEEK_CUR);
502 return (
Xroot.myFD(fildes) ?
Xroot.Ftruncate (fildes, offset)
503 :
Xunix.Ftruncate64(fildes, offset));
515 size_t bytes, rc = 0;
516 int fd = fileno(stream);
518 if (!
Xroot.myFD(fd))
return Xunix.Fwrite(ptr, size, nitems, stream);
520 bytes =
Xroot.Write(fd, ptr, size*nitems);
524 if (bytes > 0 && size) rc = bytes/size;
535#if defined(__linux__) || defined(__GNU__) || (defined(__FreeBSD_kernel__) && defined(__GLIBC__))
538long long XrdPosix_Getxattr (
const char *path,
const char *name,
void *value,
539 unsigned long long size)
541 char *myPath, buff[2048];
543 if (!(myPath =
XrootPath.URL(path, buff,
sizeof(buff))))
544 return Xunix.Getxattr(path, name, value, size);
546 return Xroot.Getxattr(myPath, name, value, size);
555#if defined(__linux__) || defined(__GNU__) || (defined(__FreeBSD_kernel__) && defined(__GLIBC__))
558long long XrdPosix_Lgetxattr (
const char *path,
const char *name,
void *value,
559 unsigned long long size)
561 if (
XrootPath.URL(path, 0, 0)) {errno = ENOTSUP;
return -1;}
562 return Xunix.Lgetxattr(path, name, value, size);
578 return (
Xroot.myFD(fildes) ?
Xroot.Lseek (fildes, offset, whence)
579 :
Xunix.Lseek64(fildes, offset, whence));
591 char *myPath, buff[2048];
595 if (!path) {errno = EFAULT;
return -1;}
599 return (!(myPath =
XrootPath.URL(path, buff,
sizeof(buff)))
600#
if defined(__linux__) and defined(_STAT_VER)
601 ?
Xunix.Lstat64(_STAT_VER, path, (
struct stat64 *)buf)
605 :
Xroot.Stat(myPath, buf));
617 char *myPath, buff[2048];
621 if (!path) {errno = EFAULT;
return -1;}
625 if (!(myPath =
XrootPath.URL(path, buff,
sizeof(buff))))
626 return Xunix.Mkdir(path, mode);
630 return Xroot.Mkdir(myPath, mode);
642 char *myPath, buff[2048];
648 if (!path) {errno = EFAULT;
return -1;}
652 if (!(myPath =
XrootPath.URL(path, buff,
sizeof(buff))))
653 {
if (!(oflag & O_CREAT))
return Xunix.Open64(path, oflag);
655 mode = va_arg(ap,
int);
657 return Xunix.Open64(path, oflag, (mode_t)mode);
662 if (!(oflag & O_CREAT))
return Xroot.Open(myPath, oflag);
664 mode = va_arg(ap,
int);
666 return Xroot.Open(myPath, oflag, (mode_t)mode);
678 char *myPath, buff[2048];
682 if (!path) {errno = EFAULT;
return 0;}
686 if (!(myPath =
XrootPath.URL(path, buff,
sizeof(buff))))
687 return Xunix.Opendir(path);
691 return Xroot.Opendir(myPath);
706 :
Xunix.Pathconf(path, name));
722 return (
Xroot.myFD(fildes) ?
Xroot.Pread (fildes, buf, nbyte, offset)
723 :
Xunix.Pread64(fildes, buf, nbyte, offset));
739 return (
Xroot.myFD(fildes) ?
Xroot.Pwrite (fildes, buf, nbyte, offset)
740 :
Xunix.Pwrite64(fildes, buf, nbyte, offset));
755 return (
Xroot.myFD(fildes) ?
Xroot.Read(fildes, buf, nbyte)
756 :
Xunix.Read(fildes, buf, nbyte));
771 return (
Xroot.myFD(fildes) ?
Xroot.Readv(fildes,
iov, iovcnt)
772 :
Xunix.Readv(fildes,
iov, iovcnt));
789 return (
Xroot.isXrootdDir(dirp) ?
Xroot.Readdir(dirp)
790 :
Xunix.Readdir(dirp));
798 return (
Xroot.isXrootdDir(dirp) ?
Xroot.Readdir64(dirp)
799 :
Xunix.Readdir64(dirp));
814 return (
Xroot.isXrootdDir(dirp) ?
Xroot.Readdir_r(dirp,entry,result)
815 :
Xunix.Readdir_r(dirp,entry,result));
823 return (
Xroot.isXrootdDir(dirp) ?
Xroot.Readdir64_r(dirp,entry,result)
824 :
Xunix.Readdir64_r(dirp,entry,result));
836 char *oldPath, buffold[2048], *newPath, buffnew[2048];
840 if (!oldpath || !newpath) {errno = EFAULT;
return -1;}
844 if (!(oldPath =
XrootPath.URL(oldpath, buffold,
sizeof(buffold)))
845 || !(newPath =
XrootPath.URL(newpath, buffnew,
sizeof(buffnew))))
846 return Xunix.Rename(oldpath, newpath);
850 return Xroot.Rename(oldPath, newPath);
865 return (
Xroot.isXrootdDir(dirp) ?
Xroot.Rewinddir(dirp)
866 :
Xunix.Rewinddir(dirp));
878 char *myPath, buff[2048];
882 if (!path) {errno = EFAULT;
return -1;}
886 if (!(myPath =
XrootPath.URL(path, buff,
sizeof(buff))))
887 return Xunix.Rmdir(path);
891 return Xroot.Rmdir(myPath);
906 (
Xroot.isXrootdDir(dirp) ?
Xroot.Seekdir(dirp, loc)
907 :
Xunix.Seekdir(dirp, loc));
919 char *myPath, buff[2048];
923 if (!path) {errno = EFAULT;
return -1;}
927 return (!(myPath =
XrootPath.URL(path, buff,
sizeof(buff)))
928#
if defined(__linux__) and defined(_STAT_VER)
929 ?
Xunix.Stat64(_STAT_VER, path, (
struct stat64 *)buf)
933 :
Xroot.Stat(myPath, buf));
945 char *myPath, buff[2048];
949 if (!path) {errno = EFAULT;
return -1;}
953 return ((myPath =
XrootPath.URL(path, buff,
sizeof(buff)))
954 ?
Xroot.Statfs(myPath, buf)
967 char *myPath, buff[2048];
971 if (!path) {errno = EFAULT;
return -1;}
975 return ((myPath =
XrootPath.URL(path, buff,
sizeof(buff)))
976 ?
Xroot.Statvfs(myPath, buf)
992 return (
Xroot.isXrootdDir(dirp) ?
Xroot.Telldir(dirp)
993 :
Xunix.Telldir(dirp));
1005 char *myPath, buff[2048];
1009 if (!path) {errno = EFAULT;
return -1;}
1013 if (!(myPath =
XrootPath.URL(path, buff,
sizeof(buff))))
1014 return Xunix.Truncate64(path, offset);
1018 return Xroot.Truncate(myPath, offset);
1030 char *myPath, buff[2048];
1034 if (!path) {errno = EFAULT;
return -1;}
1038 if (!(myPath =
XrootPath.URL(path, buff,
sizeof(buff))))
1039 return Xunix.Unlink(path);
1043 return Xroot.Unlink(myPath);
1058 return (
Xroot.myFD(fildes) ?
Xroot.Write(fildes, buf, nbyte)
1059 :
Xunix.Write(fildes, buf, nbyte));
1074 return (
Xroot.myFD(fildes) ?
Xroot.Writev(fildes,
iov, iovcnt)
1075 :
Xunix.Writev(fildes,
iov, iovcnt));
1085 return (0 !=
XrootPath.URL(path, 0, 0));
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_Write(int fildes, const void *buf, unsigned long long nbyte)
long long XrdPosix_Lseek(int fildes, long long offset, int whence)
long long XrdPosix_Writev(int fildes, const struct iovec *iov, int iovcnt)
int XrdPosix_Closedir(DIR *dirp)
int XrdPosix_Fsync(int fildes)
static void fseterr(FILE *fp)
int XrdPosix_isMyPath(const char *path)
long long XrdPosix_Ftello(FILE *stream)
int XrdPosix_Open(const char *path, int oflag,...)
void XrdPosix_Rewinddir(DIR *dirp)
long long XrdPosix_Readv(int fildes, const struct iovec *iov, int iovcnt)
int XrdPosix_Readdir64_r(DIR *dirp, struct dirent64 *entry, struct dirent64 **result)
int XrdPosix_Close(int fildes)
void XrdPosix_Seekdir(DIR *dirp, long loc)
int XrdPosix_Rmdir(const char *path)
int XrdPosix_Chdir(const char *path)
int XrdPosix_Stat(const char *path, struct stat *buf)
int XrdPosix_Rename(const char *oldpath, const char *newpath)
int XrdPosix_Fcntl(int fd, int cmd,...)
int XrdPosix_Fseek(FILE *stream, long offset, int whence)
long XrdPosix_Ftell(FILE *stream)
static void fseteof(FILE *fp)
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_Mkdir(const char *path, mode_t mode)
long long XrdPosix_Read(int fildes, void *buf, unsigned long long nbyte)
int XrdPosix_Fflush(FILE *stream)
DIR * XrdPosix_Opendir(const char *path)
XrdPosixXrootPath XrootPath
long XrdPosix_Telldir(DIR *dirp)
int XrdPosix_Lstat(const char *path, struct stat *buf)
int XrdPosix_Creat(const char *path, mode_t mode)
int XrdPosix_Statvfs(const char *path, struct statvfs *buf)
int XrdPosix_Acl(const char *path, int cmd, int nentries, void *aclbufp)
int XrdPosix_Fstat(int fildes, struct stat *buf)
FILE * XrdPosix_Fopen(const char *path, const char *mode)
size_t XrdPosix_Fwrite(const void *ptr, size_t size, size_t nitems, FILE *stream)
int XrdPosix_Fclose(FILE *stream)
int XrdPosix_Fdatasync(int fildes)
int XrdPosix_Ftruncate(int fildes, long long offset)
long XrdPosix_Pathconf(const char *path, int name)
int XrdPosix_Truncate(const char *path, long long offset)
int XrdPosix_Unlink(const char *path)
char * XrdPosix_URL(const char *path, char *buff, int blen)
struct dirent64 * XrdPosix_Readdir64(DIR *dirp)
size_t XrdPosix_Fread(void *ptr, size_t size, size_t nitems, FILE *stream)
int XrdPosix_Fseeko(FILE *stream, long long offset, int whence)
int XrdPosix_Access(const char *path, int amode)
struct dirent * XrdPosix_Readdir(DIR *dirp)
POSIX interface to XRootD with some extensions, as noted.
static const int isStream