10 using namespace IOFlags;
15 throwStorageError(
"FileDuplicateError",
"Calling File::sysduplicate()",
"dup()", errno);
27 openflags |= O_RDONLY;
29 openflags |= O_WRONLY;
35 openflags |= O_APPEND;
55 openflags |= O_NOCTTY;
57 if ((newfd = ::open(
name, openflags, perms)) == -1)
65 while (
s == -1 && errno == EINTR);
83 std::vector<iovec> bufs(buffers);
85 bufs[
i].iov_len = into[
i].
size();
86 bufs[
i].iov_base = (caddr_t)into[
i].
data();
91 n = ::readv(
fd(), &bufs[0], buffers);
92 while (
n == -1 && errno == EINTR);
107 s = ::pread(
fd(), into,
n,
pos);
108 while (
s == -1 && errno == EINTR);
120 while (
s == -1 && errno == EINTR);
122 if (
s == -1 && errno != EWOULDBLOCK)
125 return s >= 0 ?
s : 0;
138 std::vector<iovec> bufs(buffers);
140 bufs[
i].iov_len = from[
i].
size();
141 bufs[
i].iov_base = (caddr_t)from[
i].
data();
146 n = ::writev(
fd(), &bufs[0], buffers);
147 while (
n == -1 && errno == EINTR);
162 s = ::pwrite(
fd(), from,
n,
pos);
163 while (
s == -1 && errno == EINTR);
180 if (fstat(
fd, &
info) == -1)
189 assert(whence == CURRENT || whence ==
SET || whence == END);
192 int mywhence = (whence ==
SET ? SEEK_SET : whence == CURRENT ? SEEK_CUR : SEEK_END);
194 throwStorageError(
"FilePositionError",
"Calling File::position()",
"lseek()", errno);
203 if (ftruncate(
fd,
size) == -1)
204 throwStorageError(
"FileResizeError",
"Calling File::resize()",
"ftruncate()", errno);
211 #if _POSIX_SYNCHRONIZED_IO > 0 212 if (fdatasync(
fd) == -1)
213 throwStorageError(
"FileFlushError",
"Calling File::flush()",
"fdatasync()", errno);
214 #elif _POSIX_FSYNC > 0 221 int ret = ::close(
fd);
void throwStorageError(const char *category, const char *context, const char *call, int error)
ret
prodAgent to be discontinued
IOSize syswrite(const void *from, IOSize n)
IOSize syswritev(const IOBuffer *from, IOSize length)
static void sysopen(const char *name, int flags, int perms, IOFD &newfd, unsigned &newflags)
static IOFD sysduplicate(IOFD fd)
IOSize write(const void *from, IOSize n) override
IOSize readv(IOBuffer *into, IOSize length) override
IOOffset size() const override
void resize(IOOffset size) override
char data[epos_bytes_allocation]
constexpr int EDM_IOFD_INVALID
virtual IOOffset position() const
static bool sysclose(IOFD fd, int *error=nullptr)