46 # ifndef WIN32_LEAN_AND_MEAN
47 # define WIN32_LEAN_AND_MEAN
55 using ssize_t = SSIZE_T;
58 # include <sys/mman.h>
59 # include <sys/types.h>
60 # include <sys/stat.h>
61 # include <sys/fcntl.h>
71 inline int raw_open(
const char * pathname,
int flags,
int mode)
73 return ::_open(pathname, flags, mode);
76 inline int raw_open(
const char * pathname,
int flags)
78 return ::_open(pathname, flags);
86 inline int raw_lseek(
int fd,
long offset,
int whence)
88 return ::_lseek(fd, offset, whence);
91 inline int raw_read(
int fd,
void * buffer, std::size_t count)
93 return ::_read(fd, buffer, count);
96 inline int raw_write(
int fd,
const void * buffer, std::size_t count)
98 return ::_write(fd, buffer, count);
103 return ::_chsize(fd, length);
112 inline int raw_open(
const char * pathname,
int flags,
int mode)
114 return ::open(pathname, flags, mode);
117 inline int raw_open(
const char * pathname,
int flags)
119 return ::open(pathname, flags);
127 inline off_t
raw_lseek(
int fd, off_t offset,
int whence)
129 return ::lseek(fd, offset, whence);
132 inline ssize_t
raw_read(
int fd,
void * buffer, std::size_t count)
134 return ::read(fd, buffer, count);
137 inline ssize_t
raw_write(
int fd,
const void * buffer, std::size_t count)
139 return ::write(fd, buffer, count);
144 return ::ftruncate(fd, length);
154 ::fstore_t store = {F_ALLOCATEALL | F_ALLOCATECONTIG, F_PEOFPOSMODE, 0, length, 0};
155 if (::fcntl(fd, F_PREALLOCATE, &store) != -1)
159 store.fst_flags = F_ALLOCATEALL;
160 if (::fcntl(fd, F_PREALLOCATE, &store) != -1)
172 if (::fallocate(fd, 0, 0, length) == 0)
176 if (::posix_fallocate(fd, 0, length) == 0)
190 off_t old_pos =
raw_lseek(fd, 0, SEEK_CUR);
193 if (
raw_lseek(fd, length - 1, SEEK_SET) == -1)
198 ssize_t written =
raw_write(fd, &buffer, 1);
201 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)