44 #if defined HAVE_PREAD && defined PREAD_PROTOTYPE
47 #if defined HAVE_PWRITE && defined PWRITE_PROTOTYPE
57 if (errno != ENOENT) {
74 #ifdef F_DUPFD_CLOEXEC
78 if (fd < 0 && errno == EINVAL)
85 (void)fcntl(fd, F_SETFD, FD_CLOEXEC);
88 int save_errno = errno;
94 memset(toclose, 0,
sizeof(toclose));
100 int save_errno = errno;
108 (void)fcntl(fd, F_SETFD, FD_CLOEXEC);
129 if (anew) flags |= O_CREAT | O_TRUNC;
130 int fd =
::open(filename, flags, 0666);
135 io_read(
int fd,
char * p,
size_t n,
size_t min)
139 ssize_t c = read(fd, p, n);
142 if (total >= min)
break;
145 if (errno == EINTR)
continue;
160 ssize_t c = write(fd, p, n);
162 if (errno == EINTR)
continue;
180 #ifdef HAVE_POSIX_FADVISE
187 return posix_fadvise(fd, o, n, POSIX_FADV_WILLNEED) == 0;
200 ssize_t c = pread(fd, p, n, o);
202 if (
usual(c == ssize_t(n)))
210 if (errno == EINTR)
continue;
218 if (
rare(lseek(fd, o, SEEK_SET) < 0))
221 ssize_t c = read(fd, p, n);
223 if (
usual(c == ssize_t(n)))
230 if (errno == EINTR)
continue;
248 ssize_t c = pwrite(fd, p, n, o);
250 if (
usual(c == ssize_t(n)))
255 if (errno == EINTR)
continue;
263 if (
rare(lseek(fd, o, SEEK_SET) < 0))
266 ssize_t c = write(fd, p, n);
268 if (
usual(c == ssize_t(n)))
273 if (errno == EINTR)
continue;
298 if (
posixy_rename(tmp_file.c_str(), real_file.c_str()) < 0) {
300 if (errno == EXDEV && --retries > 0)
goto retry;
307 int saved_errno = errno;
308 if (unlink(tmp_file.c_str()) == 0 || errno != ENOENT) {
DatabaseCorruptError indicates database corruption was detected.
DatabaseError indicates some sort of database related error.
Hierarchy of classes which Xapian can throw as exceptions.
void io_read_block(int fd, char *p, size_t n, off_t b, off_t o)
Read block b size n bytes into buffer p from file descriptor fd, offset o.
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.
size_t io_read(int fd, char *p, size_t n, size_t min)
Read n bytes (or until EOF) into block pointed to by p from file descriptor fd.
static int move_to_higher_fd_(int fd)
bool io_tmp_rename(const std::string &tmp_file, const std::string &real_file)
Rename a temporary file to its final position.
void io_write_block(int fd, const char *p, size_t n, off_t b, off_t o)
Write block b size n bytes from buffer p to file descriptor fd, offset o.
static void throw_block_error(const char *s, off_t b, int e=0)
static int move_to_higher_fd(int fd)
Wrappers for low-level POSIX I/O routines.
bool io_readahead_block(int, size_t, off_t, off_t=0)
Readahead block b size n bytes from file descriptor fd.
WritableDatabase open()
Construct a WritableDatabase object for a new, empty InMemory database.
string str(int value)
Convert int to std::string.
Define the XAPIAN_NORETURN macro.
Various assertion macros.
Provides wrappers with POSIXy semantics.
#define posixy_rename(F, T)
<unistd.h>, but with compat.
Convert types to std::string.