34 #include <sys/param.h>
35 #include <sys/types.h>
61 #include <stdio_ext.h>
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))))
141 int 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));
205 return XrdPosix_Open(path, O_WRONLY | O_CREAT | O_TRUNC, mode);
217 int nullfd = fileno(stream);
242 theArg = va_arg(ap,
void *);
268 #if defined(__linux__) || defined(__GNU__) || (defined(__FreeBSD_kernel__) && defined(__GLIBC__))
271 long long XrdPosix_Fgetxattr (
int fd,
const char *name,
void *value,
272 unsigned long long size)
274 if (
Xroot.
myFD(fd)) {errno = ENOTSUP;
return -1;}
291 if (!stream || !
Xroot.
myFD(fileno(stream)))
302 #define ISMODE(x) !strcmp(mode, x)
308 char *myPath, buff[2048];
314 if (!(myPath =
XrootPath.
URL(path, buff,
sizeof(buff))))
327 else {errno = EINVAL;
return 0;}
336 if (!(stream = fdopen(fd, mode)))
355 int fd = fileno(stream);
359 bytes =
Xroot.
Read(fd, ptr, size*nitems);
363 if (bytes > 0 && size) rc = bytes/size;
364 else if (bytes < 0)
fseterr(stream);
385 return (
Xroot.
Lseek(fileno(stream), offset, whence) < 0 ? -1 : 0);
403 return (
Xroot.
Lseek(fileno(stream), offset, whence) < 0 ? -1 : 0);
420 #
if defined(__linux__) and defined(_STAT_VER)
428 int XrdPosix_FstatV(
int ver,
int fildes,
struct stat *buf)
470 return static_cast<long>(
Xroot.
Lseek(fileno(stream), 0, SEEK_CUR));
487 return Xroot.
Lseek(fileno(stream), 0, SEEK_CUR);
515 size_t bytes, rc = 0;
516 int fd = fileno(stream);
524 if (bytes > 0 && size) rc = bytes/size;
535 #if defined(__linux__) || defined(__GNU__) || (defined(__FreeBSD_kernel__) && defined(__GLIBC__))
538 long 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))))
555 #if defined(__linux__) || defined(__GNU__) || (defined(__FreeBSD_kernel__) && defined(__GLIBC__))
558 long 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;}
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)
617 char *myPath, buff[2048];
621 if (!path) {errno = EFAULT;
return -1;}
625 if (!(myPath =
XrootPath.
URL(path, buff,
sizeof(buff))))
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);
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))))
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))))
878 char *myPath, buff[2048];
882 if (!path) {errno = EFAULT;
return -1;}
886 if (!(myPath =
XrootPath.
URL(path, buff,
sizeof(buff))))
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)
945 char *myPath, buff[2048];
949 if (!path) {errno = EFAULT;
return -1;}
953 return ((myPath =
XrootPath.
URL(path, buff,
sizeof(buff)))
967 char *myPath, buff[2048];
971 if (!path) {errno = EFAULT;
return -1;}
975 return ((myPath =
XrootPath.
URL(path, buff,
sizeof(buff)))
1005 char *myPath, buff[2048];
1009 if (!path) {errno = EFAULT;
return -1;}
1013 if (!(myPath =
XrootPath.
URL(path, buff,
sizeof(buff))))
1030 char *myPath, buff[2048];
1034 if (!path) {errno = EFAULT;
return -1;}
1038 if (!(myPath =
XrootPath.
URL(path, buff,
sizeof(buff))))
int stat(const char *path, struct stat *buf)
int statvfs(const char *path, struct statvfs *buf)
int statfs(const char *path, struct statfs *buf)
int statvfs64(const char *path, struct statvfs64 *buf)
int fseek(FILE *stream, long offset, int whence)
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)
FILE * XrdPosix_Fopen(const char *path, const char *mode)
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)
char * XrdPosix_URL(const char *path, char *buff, int blen)
XrdPosixXrootPath XrootPath
DIR * XrdPosix_Opendir(const char *path)
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)
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)
struct dirent64 * XrdPosix_Readdir64(DIR *dirp)
long XrdPosix_Pathconf(const char *path, int name)
int XrdPosix_Truncate(const char *path, long long offset)
struct dirent * XrdPosix_Readdir(DIR *dirp)
int XrdPosix_Unlink(const char *path)
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)
Retv_Opendir(* Opendir)(Args_Opendir)
Retv_Mkdir(* Mkdir)(Args_Mkdir)
Retv_Readdir64(* Readdir64)(Args_Readdir64)
Retv_Fflush(* Fflush)(Args_Fflush)
Retv_Fstat64(* Fstat64)(Args_Fstat64)
Retv_Fclose(* Fclose)(Args_Fclose)
Retv_Fseek(* Fseek)(Args_Fseek)
Retv_Fwrite(* Fwrite)(Args_Fwrite)
Retv_Acl(* Acl)(Args_Acl)
Retv_Writev(* Writev)(Args_Writev)
Retv_Read(* Read)(Args_Read)
Retv_Fsync(* Fsync)(Args_Fsync)
Retv_Rename(* Rename)(Args_Rename)
Retv_Close(* Close)(Args_Close)
Retv_Statfs64(* Statfs64)(Args_Statfs64)
Retv_Lgetxattr(* Lgetxattr)(Args_Lgetxattr)
Retv_Ftruncate64(* Ftruncate64)(Args_Ftruncate64)
Retv_Rewinddir(* Rewinddir)(Args_Rewinddir)
Retv_Readdir(* Readdir)(Args_Readdir)
Retv_Lseek64(* Lseek64)(Args_Lseek64)
Retv_Statvfs64(* Statvfs64)(Args_Statvfs64)
Retv_Truncate64(* Truncate64)(Args_Truncate64)
Retv_Ftell(* Ftell)(Args_Ftell)
Retv_Fread(* Fread)(Args_Fread)
Retv_Open64(* Open64)(Args_Open64)
Retv_Fopen64(* Fopen64)(Args_Fopen64)
Retv_Telldir(* Telldir)(Args_Telldir)
Retv_Fseeko64(* Fseeko64)(Args_Fseeko64)
Retv_Readv(* Readv)(Args_Readv)
Retv_Stat64(* Stat64)(Args_Stat64)
Retv_Pread64(* Pread64)(Args_Pread64)
Retv_Readdir64_r(* Readdir64_r)(Args_Readdir64_r)
Retv_Fcntl64(* Fcntl64)(Args_Fcntl64)
Retv_Seekdir(* Seekdir)(Args_Seekdir)
Retv_Lstat64(* Lstat64)(Args_Lstat64)
Retv_Chdir(* Chdir)(Args_Chdir)
Retv_Getxattr(* Getxattr)(Args_Getxattr)
Retv_Access(* Access)(Args_Access)
Retv_Closedir(* Closedir)(Args_Closedir)
Retv_Pathconf(* Pathconf)(Args_Pathconf)
Retv_Write(* Write)(Args_Write)
Retv_Readdir_r(* Readdir_r)(Args_Readdir_r)
Retv_Rmdir(* Rmdir)(Args_Rmdir)
Retv_Fgetxattr(* Fgetxattr)(Args_Fgetxattr)
Retv_Unlink(* Unlink)(Args_Unlink)
Retv_Pwrite64(* Pwrite64)(Args_Pwrite64)
Retv_Ftello64(* Ftello64)(Args_Ftello64)
char * URL(const char *path, char *buff, int blen)
void CWD(const char *path)
POSIX interface to XRootD with some extensions, as noted.
static ssize_t Readv(int fildes, const struct iovec *iov, int iovcnt)
Readv() conforms to POSIX.1-2001 readv()
static ssize_t Pread(int fildes, void *buf, size_t nbyte, off_t offset)
Pread() conforms to POSIX.1-2001 pread()
static int Closedir(DIR *dirp)
Closedir() conforms to POSIX.1-2001 closedir()
static void Seekdir(DIR *dirp, long loc)
Seekdir() conforms to POSIX.1-2001 seekdir()
static const int isStream
static int Stat(const char *path, struct stat *buf)
Stat() conforms to POSIX.1-2001 stat()
static int Mkdir(const char *path, mode_t mode)
Mkdir() conforms to POSIX.1-2001 mkdir()
static int Unlink(const char *path)
Unlink() conforms to POSIX.1-2001 unlink()
static int Rmdir(const char *path)
Rmdir() conforms to POSIX.1-2001 rmdir()
static void Rewinddir(DIR *dirp)
Rewinddir() conforms to POSIX.1-2001 rewinddir()
static int Rename(const char *oldpath, const char *newpath)
Rename() conforms to POSIX.1-2001 rename()
static int Close(int fildes)
Close() conforms to POSIX.1-2001 close()
static int Statvfs(const char *path, struct statvfs *buf)
Statvfs() conforms to POSIX.1-2001 statvfs()
static ssize_t Write(int fildes, const void *buf, size_t nbyte)
Write() conforms to POSIX.1-2001 write()
static struct dirent * Readdir(DIR *dirp)
static int Readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result)
static ssize_t Writev(int fildes, const struct iovec *iov, int iovcnt)
Writev() conforms to POSIX.1-2001 writev()
static struct dirent64 * Readdir64(DIR *dirp)
static int Ftruncate(int fildes, off_t offset)
Ftruncate() conforms to POSIX.1-2001 ftruncate()
static long Telldir(DIR *dirp)
Telldir() conforms to POSIX.1-2001 telldir()
static bool isXrootdDir(DIR *dirp)
static int Access(const char *path, int amode)
Access() conforms to POSIX.1-2001 access()
static DIR * Opendir(const char *path)
Opendir() conforms to POSIX.1-2001 opendir()
static int Fsync(int fildes)
Fsync() conforms to POSIX.1-2001 fsync()
static long long Getxattr(const char *path, const char *name, void *value, unsigned long long size)
static int Statfs(const char *path, struct statfs *buf)
static int Readdir64_r(DIR *dirp, struct dirent64 *entry, struct dirent64 **result)
static ssize_t Read(int fildes, void *buf, size_t nbyte)
Read() conforms to POSIX.1-2001 read()
static int Fstat(int fildes, struct stat *buf)
Fstat() conforms to POSIX.1-2001 fstat()
static off_t Lseek(int fildes, off_t offset, int whence)
Lseek() conforms to POSIX.1-2001 lseek()
static int Open(const char *path, int oflag, mode_t mode=0, XrdPosixCallBack *cbP=0)
static ssize_t Pwrite(int fildes, const void *buf, size_t nbyte, off_t offset)
Pwrite() conforms to POSIX.1-2001 pwrite()
static int Truncate(const char *path, off_t offset)
Telldir() conforms to POSIX.1-2001 telldir()