46 # ifndef WIN32_LEAN_AND_MEAN
47 # define WIN32_LEAN_AND_MEAN
58 using ssize_t = SSIZE_T;
62 # include <sys/mman.h>
63 # include <sys/types.h>
64 # include <sys/stat.h>
75 inline int raw_open(
const char * pathname,
int flags,
int mode)
77 return ::_open(pathname, flags, mode);
80 inline int raw_open(
const char * pathname,
int flags)
82 return ::_open(pathname, flags);
90 inline int raw_lseek(
int fd,
long offset,
int whence)
92 return ::_lseek(fd, offset, whence);
95 inline int raw_read(
int fd,
void * buffer, std::size_t count)
97 return ::_read(fd, buffer, count);
100 inline int raw_write(
int fd,
const void * buffer, std::size_t count)
102 return ::_write(fd, buffer, count);
107 return ::_chsize(fd, length);
116 inline int raw_open(
const char * pathname,
int flags,
int mode)
118 return ::open(pathname, flags, mode);
121 inline int raw_open(
const char * pathname,
int flags)
123 return ::open(pathname, flags);
131 inline off_t
raw_lseek(
int fd, off_t offset,
int whence)
133 return ::lseek(fd, offset, whence);
136 inline ssize_t
raw_read(
int fd,
void * buffer, std::size_t count)
138 return ::read(fd, buffer, count);
141 inline ssize_t
raw_write(
int fd,
const void * buffer, std::size_t count)
143 return ::write(fd, buffer, count);
148 return ::ftruncate(fd, length);
158 ::fstore_t store = {F_ALLOCATEALL | F_ALLOCATECONTIG, F_PEOFPOSMODE, 0, length, 0};
159 if (::fcntl(fd, F_PREALLOCATE, &store) != -1)
163 store.fst_flags = F_ALLOCATEALL;
164 if (::fcntl(fd, F_PREALLOCATE, &store) != -1)
176 if (::fallocate(fd, 0, 0, length) == 0)
184 # elif defined(__OpenBSD__)
186 if (::ftruncate(fd, length) == 0)
192 const int res = ::posix_fallocate(fd, 0, length);
208 off_t old_pos =
raw_lseek(fd, 0, SEEK_CUR);
211 if (
raw_lseek(fd, length - 1, SEEK_SET) == -1)
216 ssize_t written =
raw_write(fd, &buffer, 1);
219 if (
raw_lseek(fd, old_pos, SEEK_SET) == -1)
int raw_ftruncate(int fd, long length)
int raw_lseek(int fd, long offset, int whence)
int raw_write(int fd, const void *buffer, std::size_t count)
int raw_fallocate(int fd, long length)
int raw_open(const char *pathname, int flags, int mode)
int raw_read(int fd, void *buffer, std::size_t count)