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__))
271ssize_t XrdPosix_Fgetxattr (
int fd,
const char *name,
void *value,
size_t size)
273 if (
Xroot.myFD(fd)) {errno = ENOTSUP;
return -1;}
274 return Xunix.Fgetxattr(fd, name, value, size);
290 if (!stream || !
Xroot.myFD(fileno(stream)))
291 return Xunix.Fflush(stream);
293 return Xroot.Fsync(fileno(stream));
301#define ISMODE(x) !strcmp(mode, x)
307 char *myPath, buff[2048];
313 if (!(myPath =
XrootPath.URL(path, buff,
sizeof(buff))))
314 return Xunix.Fopen64(path, mode);
322 | O_CREAT | O_APPEND;
327 | O_CREAT | O_APPEND;
328 else {errno = EINVAL;
return 0;}
337 if (!(stream = fdopen(fd, mode)))
338 {erc = errno;
Xroot.Close(fd); errno = erc;}
356 int fd = fileno(stream);
358 if (!
Xroot.myFD(fd))
return Xunix.Fread(ptr, size, nitems, stream);
360 bytes =
Xroot.Read(fd, ptr, size*nitems);
364 if (bytes > 0 && size) rc = bytes/size;
365 else if (bytes < 0)
fseterr(stream);
383 if (!
Xroot.myFD(fileno(stream)))
384 return Xunix.Fseek( stream, offset, whence);
386 return (
Xroot.Lseek(fileno(stream), offset, whence) < 0 ? -1 : 0);
401 if (!
Xroot.myFD(fileno(stream)))
402 return Xunix.Fseeko64(stream, offset, whence);
404 return (
Xroot.Lseek(fileno(stream), offset, whence) < 0 ? -1 : 0);
419 return (
Xroot.myFD(fildes)
420 ?
Xroot.Fstat(fildes, buf)
421#
if defined(__linux__) and defined(_STAT_VER)
422 :
Xunix.Fstat64(_STAT_VER, fildes, (
struct stat64 *)buf));
429int XrdPosix_FstatV(
int ver,
int fildes,
struct stat *buf)
431 return (
Xroot.myFD(fildes)
432 ?
Xroot.Fstat(fildes, buf)
434 :
Xunix.Fstat64(ver, fildes, (
struct stat64 *)buf));
453 return (
Xroot.myFD(fildes) ?
Xroot.Fsync(fildes)
454 :
Xunix.Fsync(fildes));
469 if (!
Xroot.myFD(fileno(stream)))
return Xunix.Ftell(stream);
471 return static_cast<long>(
Xroot.Lseek(fileno(stream), 0, SEEK_CUR));
486 if (!
Xroot.myFD(fileno(stream)))
return Xunix.Ftello64(stream);
488 return Xroot.Lseek(fileno(stream), 0, SEEK_CUR);
503 return (
Xroot.myFD(fildes) ?
Xroot.Ftruncate (fildes, offset)
504 :
Xunix.Ftruncate64(fildes, offset));
516 size_t bytes, rc = 0;
517 int fd = fileno(stream);
519 if (!
Xroot.myFD(fd))
return Xunix.Fwrite(ptr, size, nitems, stream);
521 bytes =
Xroot.Write(fd, ptr, size*nitems);
525 if (bytes > 0 && size) rc = bytes/size;
536#if defined(__linux__) || defined(__GNU__) || (defined(__FreeBSD_kernel__) && defined(__GLIBC__))
539ssize_t XrdPosix_Getxattr (
const char *path,
const char *name,
void *value,
size_t 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__))
558ssize_t XrdPosix_Lgetxattr (
const char *path,
const char *name,
void *value,
size_t size)
560 if (
XrootPath.URL(path, 0, 0)) {errno = ENOTSUP;
return -1;}
561 return Xunix.Lgetxattr(path, name, value, size);
577 return (
Xroot.myFD(fildes) ?
Xroot.Lseek (fildes, offset, whence)
578 :
Xunix.Lseek64(fildes, offset, whence));
590 char *myPath, buff[2048];
594 if (!path) {errno = EFAULT;
return -1;}
598 return (!(myPath =
XrootPath.URL(path, buff,
sizeof(buff)))
599#
if defined(__linux__) and defined(_STAT_VER)
600 ?
Xunix.Lstat64(_STAT_VER, path, (
struct stat64 *)buf)
604 :
Xroot.Stat(myPath, buf));
616 char *myPath, buff[2048];
620 if (!path) {errno = EFAULT;
return -1;}
624 if (!(myPath =
XrootPath.URL(path, buff,
sizeof(buff))))
625 return Xunix.Mkdir(path, mode);
629 return Xroot.Mkdir(myPath, mode);
641 char *myPath, buff[2048];
647 if (!path) {errno = EFAULT;
return -1;}
651 if (!(myPath =
XrootPath.URL(path, buff,
sizeof(buff))))
652 {
if (!(oflag & O_CREAT))
return Xunix.Open64(path, oflag);
654 mode = va_arg(ap,
int);
656 return Xunix.Open64(path, oflag, (mode_t)mode);
661 if (!(oflag & O_CREAT))
return Xroot.Open(myPath, oflag);
663 mode = va_arg(ap,
int);
665 return Xroot.Open(myPath, oflag, (mode_t)mode);
677 char *myPath, buff[2048];
681 if (!path) {errno = EFAULT;
return 0;}
685 if (!(myPath =
XrootPath.URL(path, buff,
sizeof(buff))))
686 return Xunix.Opendir(path);
690 return Xroot.Opendir(myPath);
705 :
Xunix.Pathconf(path, name));
720 return (
Xroot.myFD(fildes) ?
Xroot.Pread (fildes, buf, nbyte, offset)
721 :
Xunix.Pread64(fildes, buf, nbyte, offset));
736 return (
Xroot.myFD(fildes) ?
Xroot.Pwrite (fildes, buf, nbyte, offset)
737 :
Xunix.Pwrite64(fildes, buf, nbyte, offset));
752 return (
Xroot.myFD(fildes) ?
Xroot.Read(fildes, buf, nbyte)
753 :
Xunix.Read(fildes, buf, nbyte));
768 return (
Xroot.myFD(fildes) ?
Xroot.Readv(fildes,
iov, iovcnt)
769 :
Xunix.Readv(fildes,
iov, iovcnt));
786 return (
Xroot.isXrootdDir(dirp) ?
Xroot.Readdir(dirp)
787 :
Xunix.Readdir(dirp));
795 return (
Xroot.isXrootdDir(dirp) ?
Xroot.Readdir64(dirp)
796 :
Xunix.Readdir64(dirp));
811 return (
Xroot.isXrootdDir(dirp) ?
Xroot.Readdir_r(dirp,entry,result)
812 :
Xunix.Readdir_r(dirp,entry,result));
820 return (
Xroot.isXrootdDir(dirp) ?
Xroot.Readdir64_r(dirp,entry,result)
821 :
Xunix.Readdir64_r(dirp,entry,result));
833 char *oldPath, buffold[2048], *newPath, buffnew[2048];
837 if (!oldpath || !newpath) {errno = EFAULT;
return -1;}
841 if (!(oldPath =
XrootPath.URL(oldpath, buffold,
sizeof(buffold)))
842 || !(newPath =
XrootPath.URL(newpath, buffnew,
sizeof(buffnew))))
843 return Xunix.Rename(oldpath, newpath);
847 return Xroot.Rename(oldPath, newPath);
862 return (
Xroot.isXrootdDir(dirp) ?
Xroot.Rewinddir(dirp)
863 :
Xunix.Rewinddir(dirp));
875 char *myPath, buff[2048];
879 if (!path) {errno = EFAULT;
return -1;}
883 if (!(myPath =
XrootPath.URL(path, buff,
sizeof(buff))))
884 return Xunix.Rmdir(path);
888 return Xroot.Rmdir(myPath);
903 (
Xroot.isXrootdDir(dirp) ?
Xroot.Seekdir(dirp, loc)
904 :
Xunix.Seekdir(dirp, loc));
916 char *myPath, buff[2048];
920 if (!path) {errno = EFAULT;
return -1;}
924 return (!(myPath =
XrootPath.URL(path, buff,
sizeof(buff)))
925#
if defined(__linux__) and defined(_STAT_VER)
926 ?
Xunix.Stat64(_STAT_VER, path, (
struct stat64 *)buf)
930 :
Xroot.Stat(myPath, buf));
942 char *myPath, buff[2048];
946 if (!path) {errno = EFAULT;
return -1;}
950 return ((myPath =
XrootPath.URL(path, buff,
sizeof(buff)))
951 ?
Xroot.Statfs(myPath, buf)
964 char *myPath, buff[2048];
968 if (!path) {errno = EFAULT;
return -1;}
972 return ((myPath =
XrootPath.URL(path, buff,
sizeof(buff)))
973 ?
Xroot.Statvfs(myPath, buf)
989 return (
Xroot.isXrootdDir(dirp) ?
Xroot.Telldir(dirp)
990 :
Xunix.Telldir(dirp));
1002 char *myPath, buff[2048];
1006 if (!path) {errno = EFAULT;
return -1;}
1010 if (!(myPath =
XrootPath.URL(path, buff,
sizeof(buff))))
1011 return Xunix.Truncate64(path, offset);
1015 return Xroot.Truncate(myPath, offset);
1027 char *myPath, buff[2048];
1031 if (!path) {errno = EFAULT;
return -1;}
1035 if (!(myPath =
XrootPath.URL(path, buff,
sizeof(buff))))
1036 return Xunix.Unlink(path);
1040 return Xroot.Unlink(myPath);
1055 return (
Xroot.myFD(fildes) ?
Xroot.Write(fildes, buf, nbyte)
1056 :
Xunix.Write(fildes, buf, nbyte));
1071 return (
Xroot.myFD(fildes) ?
Xroot.Writev(fildes,
iov, iovcnt)
1072 :
Xunix.Writev(fildes,
iov, iovcnt));
1082 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)
int XrdPosix_Truncate(const char *path, off_t offset)
ssize_t XrdPosix_Read(int fildes, void *buf, size_t nbyte)
int XrdPosix_Closedir(DIR *dirp)
int XrdPosix_Fsync(int fildes)
ssize_t XrdPosix_Readv(int fildes, const struct iovec *iov, int iovcnt)
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)
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_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)
int XrdPosix_Mkdir(const char *path, mode_t mode)
int XrdPosix_Fflush(FILE *stream)
DIR * XrdPosix_Opendir(const char *path)
ssize_t XrdPosix_Writev(int fildes, const struct iovec *iov, int iovcnt)
XrdPosixXrootPath XrootPath
long XrdPosix_Telldir(DIR *dirp)
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_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)
off_t XrdPosix_Lseek(int fildes, off_t offset, int whence)
ssize_t XrdPosix_Write(int fildes, const void *buf, size_t nbyte)
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_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