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);
323 | O_CREAT | O_APPEND;
328 | O_CREAT | O_APPEND;
329 else {errno = EINVAL;
return 0;}
338 if (!(stream = fdopen(fd, mode)))
339 {erc = errno;
Xroot.Close(fd); errno = erc;}
357 int fd = fileno(stream);
359 if (!
Xroot.myFD(fd))
return Xunix.Fread(ptr, size, nitems, stream);
361 bytes =
Xroot.Read(fd, ptr, size*nitems);
365 if (bytes > 0 && size) rc = bytes/size;
366 else if (bytes < 0)
fseterr(stream);
384 if (!
Xroot.myFD(fileno(stream)))
385 return Xunix.Fseek( stream, offset, whence);
387 return (
Xroot.Lseek(fileno(stream), offset, whence) < 0 ? -1 : 0);
402 if (!
Xroot.myFD(fileno(stream)))
403 return Xunix.Fseeko64(stream, offset, whence);
405 return (
Xroot.Lseek(fileno(stream), offset, whence) < 0 ? -1 : 0);
420 return (
Xroot.myFD(fildes)
421 ?
Xroot.Fstat(fildes, buf)
422#
if defined(__linux__) and defined(_STAT_VER)
423 :
Xunix.Fstat64(_STAT_VER, fildes, (
struct stat64 *)buf));
430int XrdPosix_FstatV(
int ver,
int fildes,
struct stat *buf)
432 return (
Xroot.myFD(fildes)
433 ?
Xroot.Fstat(fildes, buf)
435 :
Xunix.Fstat64(ver, fildes, (
struct stat64 *)buf));
454 return (
Xroot.myFD(fildes) ?
Xroot.Fsync(fildes)
455 :
Xunix.Fsync(fildes));
470 if (!
Xroot.myFD(fileno(stream)))
return Xunix.Ftell(stream);
472 return static_cast<long>(
Xroot.Lseek(fileno(stream), 0, SEEK_CUR));
487 if (!
Xroot.myFD(fileno(stream)))
return Xunix.Ftello64(stream);
489 return Xroot.Lseek(fileno(stream), 0, SEEK_CUR);
504 return (
Xroot.myFD(fildes) ?
Xroot.Ftruncate (fildes, offset)
505 :
Xunix.Ftruncate64(fildes, offset));
517 size_t bytes, rc = 0;
518 int fd = fileno(stream);
520 if (!
Xroot.myFD(fd))
return Xunix.Fwrite(ptr, size, nitems, stream);
522 bytes =
Xroot.Write(fd, ptr, size*nitems);
526 if (bytes > 0 && size) rc = bytes/size;
537#if defined(__linux__) || defined(__GNU__) || (defined(__FreeBSD_kernel__) && defined(__GLIBC__))
540long long XrdPosix_Getxattr (
const char *path,
const char *name,
void *value,
541 unsigned long long size)
543 char *myPath, buff[2048];
545 if (!(myPath =
XrootPath.URL(path, buff,
sizeof(buff))))
546 return Xunix.Getxattr(path, name, value, size);
548 return Xroot.Getxattr(myPath, name, value, size);
557#if defined(__linux__) || defined(__GNU__) || (defined(__FreeBSD_kernel__) && defined(__GLIBC__))
560long long XrdPosix_Lgetxattr (
const char *path,
const char *name,
void *value,
561 unsigned long long size)
563 if (
XrootPath.URL(path, 0, 0)) {errno = ENOTSUP;
return -1;}
564 return Xunix.Lgetxattr(path, name, value, size);
580 return (
Xroot.myFD(fildes) ?
Xroot.Lseek (fildes, offset, whence)
581 :
Xunix.Lseek64(fildes, offset, whence));
593 char *myPath, buff[2048];
597 if (!path) {errno = EFAULT;
return -1;}
601 return (!(myPath =
XrootPath.URL(path, buff,
sizeof(buff)))
602#
if defined(__linux__) and defined(_STAT_VER)
603 ?
Xunix.Lstat64(_STAT_VER, path, (
struct stat64 *)buf)
607 :
Xroot.Stat(myPath, buf));
619 char *myPath, buff[2048];
623 if (!path) {errno = EFAULT;
return -1;}
627 if (!(myPath =
XrootPath.URL(path, buff,
sizeof(buff))))
628 return Xunix.Mkdir(path, mode);
632 return Xroot.Mkdir(myPath, mode);
644 char *myPath, buff[2048];
650 if (!path) {errno = EFAULT;
return -1;}
654 if (!(myPath =
XrootPath.URL(path, buff,
sizeof(buff))))
655 {
if (!(oflag & O_CREAT))
return Xunix.Open64(path, oflag);
657 mode = va_arg(ap,
int);
659 return Xunix.Open64(path, oflag, (mode_t)mode);
664 if (!(oflag & O_CREAT))
return Xroot.Open(myPath, oflag);
666 mode = va_arg(ap,
int);
668 return Xroot.Open(myPath, oflag, (mode_t)mode);
680 char *myPath, buff[2048];
684 if (!path) {errno = EFAULT;
return 0;}
688 if (!(myPath =
XrootPath.URL(path, buff,
sizeof(buff))))
689 return Xunix.Opendir(path);
693 return Xroot.Opendir(myPath);
708 :
Xunix.Pathconf(path, name));
724 return (
Xroot.myFD(fildes) ?
Xroot.Pread (fildes, buf, nbyte, offset)
725 :
Xunix.Pread64(fildes, buf, nbyte, offset));
741 return (
Xroot.myFD(fildes) ?
Xroot.Pwrite (fildes, buf, nbyte, offset)
742 :
Xunix.Pwrite64(fildes, buf, nbyte, offset));
757 return (
Xroot.myFD(fildes) ?
Xroot.Read(fildes, buf, nbyte)
758 :
Xunix.Read(fildes, buf, nbyte));
773 return (
Xroot.myFD(fildes) ?
Xroot.Readv(fildes,
iov, iovcnt)
774 :
Xunix.Readv(fildes,
iov, iovcnt));
791 return (
Xroot.isXrootdDir(dirp) ?
Xroot.Readdir(dirp)
792 :
Xunix.Readdir(dirp));
800 return (
Xroot.isXrootdDir(dirp) ?
Xroot.Readdir64(dirp)
801 :
Xunix.Readdir64(dirp));
816 return (
Xroot.isXrootdDir(dirp) ?
Xroot.Readdir_r(dirp,entry,result)
817 :
Xunix.Readdir_r(dirp,entry,result));
825 return (
Xroot.isXrootdDir(dirp) ?
Xroot.Readdir64_r(dirp,entry,result)
826 :
Xunix.Readdir64_r(dirp,entry,result));
838 char *oldPath, buffold[2048], *newPath, buffnew[2048];
842 if (!oldpath || !newpath) {errno = EFAULT;
return -1;}
846 if (!(oldPath =
XrootPath.URL(oldpath, buffold,
sizeof(buffold)))
847 || !(newPath =
XrootPath.URL(newpath, buffnew,
sizeof(buffnew))))
848 return Xunix.Rename(oldpath, newpath);
852 return Xroot.Rename(oldPath, newPath);
867 return (
Xroot.isXrootdDir(dirp) ?
Xroot.Rewinddir(dirp)
868 :
Xunix.Rewinddir(dirp));
880 char *myPath, buff[2048];
884 if (!path) {errno = EFAULT;
return -1;}
888 if (!(myPath =
XrootPath.URL(path, buff,
sizeof(buff))))
889 return Xunix.Rmdir(path);
893 return Xroot.Rmdir(myPath);
908 (
Xroot.isXrootdDir(dirp) ?
Xroot.Seekdir(dirp, loc)
909 :
Xunix.Seekdir(dirp, loc));
921 char *myPath, buff[2048];
925 if (!path) {errno = EFAULT;
return -1;}
929 return (!(myPath =
XrootPath.URL(path, buff,
sizeof(buff)))
930#
if defined(__linux__) and defined(_STAT_VER)
931 ?
Xunix.Stat64(_STAT_VER, path, (
struct stat64 *)buf)
935 :
Xroot.Stat(myPath, buf));
947 char *myPath, buff[2048];
951 if (!path) {errno = EFAULT;
return -1;}
955 return ((myPath =
XrootPath.URL(path, buff,
sizeof(buff)))
956 ?
Xroot.Statfs(myPath, buf)
969 char *myPath, buff[2048];
973 if (!path) {errno = EFAULT;
return -1;}
977 return ((myPath =
XrootPath.URL(path, buff,
sizeof(buff)))
978 ?
Xroot.Statvfs(myPath, buf)
994 return (
Xroot.isXrootdDir(dirp) ?
Xroot.Telldir(dirp)
995 :
Xunix.Telldir(dirp));
1007 char *myPath, buff[2048];
1011 if (!path) {errno = EFAULT;
return -1;}
1015 if (!(myPath =
XrootPath.URL(path, buff,
sizeof(buff))))
1016 return Xunix.Truncate64(path, offset);
1020 return Xroot.Truncate(myPath, offset);
1032 char *myPath, buff[2048];
1036 if (!path) {errno = EFAULT;
return -1;}
1040 if (!(myPath =
XrootPath.URL(path, buff,
sizeof(buff))))
1041 return Xunix.Unlink(path);
1045 return Xroot.Unlink(myPath);
1060 return (
Xroot.myFD(fildes) ?
Xroot.Write(fildes, buf, nbyte)
1061 :
Xunix.Write(fildes, buf, nbyte));
1076 return (
Xroot.myFD(fildes) ?
Xroot.Writev(fildes,
iov, iovcnt)
1077 :
Xunix.Writev(fildes,
iov, iovcnt));
1087 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