20 #include <sys/types.h> 57 ssize_t
readNoInt(
int fd,
void* buf,
size_t n);
58 ssize_t
preadNoInt(
int fd,
void* buf,
size_t n, off_t offset);
61 ssize_t
writeNoInt(
int fd,
const void* buf,
size_t n);
62 ssize_t
pwriteNoInt(
int fd,
const void* buf,
size_t n, off_t offset);
63 ssize_t
writevNoInt(
int fd,
const iovec* iov,
int count);
109 ssize_t
writeFull(
int fd,
const void* buf,
size_t n);
110 ssize_t
pwriteFull(
int fd,
const void* buf,
size_t n, off_t offset);
111 ssize_t
writevFull(
int fd, iovec* iov,
int count);
112 ssize_t
pwritevFull(
int fd, iovec* iov,
int count, off_t offset);
124 template <
class Container>
131 "readFile: only containers with byte-sized elements accepted");
135 DCHECK(out.size() >= soFar);
141 if (fstat(fd, &buf) == -1) {
149 constexpr
size_t initialAlloc = 1024 * 4;
151 buf.st_size > 0 ? (
size_t(buf.st_size) + 1) : initialAlloc, num_bytes));
153 while (soFar < out.size()) {
154 const auto actual =
readFull(fd, &out[soFar], out.size() - soFar);
159 if (soFar < out.size()) {
165 out.resize(
std::min(out.size() * 3 / 2, num_bytes));
174 template <
class Container>
176 const char* file_name,
181 const auto fd =
openNoInt(file_name, O_RDONLY | O_CLOEXEC);
191 return readFile(fd, out, num_bytes);
210 template <
class Container>
212 const Container&
data,
213 const char* filename,
214 int flags = O_WRONLY | O_CREAT | O_TRUNC,
215 mode_t
mode = 0666) {
217 sizeof(data[0]) == 1,
"writeFile works with element size equal to 1");
222 bool ok = data.empty() ||
223 writeFull(fd, &data[0], data.size()) == static_cast<ssize_t>(data.size());
242 mode_t permissions = 0644);
246 mode_t permissions = 0644);
250 mode_t permissions = 0644);
262 mode_t permissions = 0644);
bool readFile(int fd, Container &out, size_t num_bytes=std::numeric_limits< size_t >::max())
ssize_t readvFull(int fd, iovec *iov, int count)
int shutdownNoInt(NetworkSocket fd, int how)
int writeFileAtomicNoThrow(StringPiece filename, iovec *iov, int count, mode_t permissions)
ssize_t preadNoInt(int fd, void *buf, size_t count, off_t offset)
ssize_t pwriteFull(int fd, const void *buf, size_t count, off_t offset)
int fdatasyncNoInt(int fd)
ssize_t readNoInt(int fd, void *buf, size_t count)
ssize_t readFull(int fd, void *buf, size_t count)
—— Concurrent Priority Queue Implementation ——
int truncateNoInt(const char *path, off_t len)
ssize_t writevFull(int fd, iovec *iov, int count)
folly::Optional< PskKeyExchangeMode > mode
ssize_t writevNoInt(int fd, const iovec *iov, int count)
ssize_t preadFull(int fd, void *buf, size_t count, off_t offset)
ssize_t readvNoInt(int fd, const iovec *iov, int count)
constexpr auto data(C &c) -> decltype(c.data())
ssize_t writeNoInt(int fd, const void *buf, size_t count)
ssize_t writeFull(int fd, const void *buf, size_t count)
int flockNoInt(int fd, int operation)
void writeFileAtomic(StringPiece filename, iovec *iov, int count, mode_t permissions)
int openNoInt(const char *name, int flags, mode_t mode)
ssize_t pwriteNoInt(int fd, const void *buf, size_t count, off_t offset)
bool writeFile(const Container &data, const char *filename, int flags=O_WRONLY|O_CREAT|O_TRUNC, mode_t mode=0666)
int dup2NoInt(int oldfd, int newfd)
int ftruncateNoInt(int fd, off_t len)
ssize_t pwritevFull(int fd, iovec *iov, int count, off_t offset)
static NetworkSocket fromFd(int fd)
ssize_t preadvFull(int fd, iovec *iov, int count, off_t offset)