12#ifdef JOEDB_HAS_BROKEN_POSIX_LOCKING
13#define JOEDB_SETLK F_SETLK
14#define JOEDB_SETLKW F_SETLKW
18#define JOEDB_SETLK F_OFD_SETLK
19#define JOEDB_SETLKW F_OFD_SETLKW
24#ifndef _FILE_OFFSET_BITS
27 sizeof(off_t) ==
sizeof(int64_t),
28 "Define the _FILE_OFFSET_BITS macro to 32 or 64 to silence this error. 64 is recommended if possible. Joedb does not check for file-size overflow."
42 std::string(action) +
' ' + file_name +
": " + strerror(errno)
48 int Posix_FD::lock(
int command,
short type, int64_t start, int64_t size)
54 lock.l_start =
off_t(start);
55 lock.l_len =
off_t(size);
95 const ssize_t result = ::pread(fd, buffer, size, offset);
98 throw_last_error(
"Reading",
"file");
100 return size_t(result);
void exclusive_lock_tail()
static constexpr int64_t last_position
void destructor_flush() noexcept
size_t pread(char *buffer, size_t size, int64_t offset) const override
static void throw_last_error(const char *action, const char *file_name)
void pwrite(const char *buffer, size_t size, int64_t offset) override
bool try_exclusive_lock(int64_t start, int64_t size)
int64_t get_size() const override
void unlock(int64_t start, int64_t size) noexcept override
void shared_lock(int64_t start, int64_t size) override
void exclusive_lock(int64_t start, int64_t size) override
Posix_FD(int fd, Open_Mode mode)
Posix_File(int fd, Open_Mode mode)
@ create_new
fails if already exists, locks the file for writing
@ write_existing
fails if does not exist or locked, locks the file for writing
@ shared_write
like write_existing_or_create_new, but does not lock the file, and does not fail if locked
@ write_existing_or_create_new
either write_existing or create_new depending on whether the file exists. Racy in Posix,...
@ write_lock
like write_existing_or_create_new, but waits instead of failing if already locked
@ read_existing
fails if does not exist