22 #ifndef XAPIAN_INCLUDED_IO_UTILS_H
23 #define XAPIAN_INCLUDED_IO_UTILS_H
26 # error config.h must be included first in each C++ source file
29 #include <sys/types.h>
109 #if defined HAVE_FDATASYNC
112 return fdatasync(fd) == 0;
113 #elif defined HAVE_FSYNC
114 return fsync(fd) == 0;
115 #elif defined __WIN32__
116 return _commit(fd) == 0;
118 # error Cannot implement io_sync() without fdatasync(), fsync(), or _commit()
135 if (fcntl(fd, F_FULLFSYNC, 0) == 0)
151 size_t io_read(
int fd,
char *
p,
size_t n,
size_t min = 0);
154 void io_write(
int fd,
const char *
p,
size_t n);
156 inline void io_write(
int fd,
const unsigned char *
p,
size_t n) {
157 io_write(fd,
reinterpret_cast<const char *
>(
p), n);
172 size_t io_pread(
int fd,
char *
p,
size_t n, off_t o,
size_t min = 0);
181 void io_pwrite(
int fd,
const char *
p,
size_t n, off_t o);
187 #ifdef HAVE_POSIX_FADVISE
194 void io_read_block(
int fd,
char *
p,
size_t n, off_t b, off_t o = 0);
197 void io_write_block(
int fd,
const char *
p,
size_t n, off_t b, off_t o = 0);
215 bool io_unlink(
const std::string & filename);
225 bool io_tmp_rename(
const std::string & tmp_file,
const std::string & real_file);
void io_write_block(int fd, const char *p, size_t n, off_t b, off_t o=0)
Write block b size n bytes from buffer p to file descriptor fd, offset o.
size_t io_read(int fd, char *p, size_t n, size_t min=0)
Read n bytes (or until EOF) into block pointed to by p from file descriptor fd.
int io_open_block_wr(const char *filename, bool anew)
Open a block-based file for writing.
bool io_unlink(const std::string &filename)
Delete a file.
void io_write(int fd, const char *p, size_t n)
Write n bytes from block pointed to by p to file descriptor fd.
int io_open_stream_rd(const char *filename)
Open a stream-based file for reading.
bool io_sync(int fd)
Ensure all data previously written to file descriptor fd has been written to disk.
void io_pwrite(int fd, const char *p, size_t n, off_t o)
Write n bytes from block pointed to by p to file descriptor fd starting at position o.
bool io_full_sync(int fd)
void io_read_block(int fd, char *p, size_t n, off_t b, off_t o=0)
Read block b size n bytes into buffer p from file descriptor fd, offset o.
int io_open_stream_wr(const char *filename, bool anew)
Open a stream-based file for writing.
bool io_readahead_block(int, size_t, off_t, off_t=0)
Readahead block b size n bytes from file descriptor fd.
bool io_tmp_rename(const std::string &tmp_file, const std::string &real_file)
Rename a temporary file to its final position.
size_t io_pread(int fd, char *p, size_t n, off_t o, size_t min=0)
Read n bytes (or until EOF) into block pointed to by p from file descriptor fd starting at position o...
int io_open_block_rd(const char *filename)
Open a block-based file for reading.
Database open(std::string_view host, unsigned int port, unsigned timeout=10000, unsigned connect_timeout=10000)
Construct a Database object for read-only access to a remote database accessed via a TCP connection.
include <fcntl.h>, but working around broken platforms.
<unistd.h>, but with compat.