43 #ifndef __PCL_IO_LOW_LEVEL_IO__ 44 #define __PCL_IO_LOW_LEVEL_IO__ 47 # ifndef WIN32_LEAN_AND_MEAN 48 # define WIN32_LEAN_AND_MEAN 56 typedef SSIZE_T ssize_t;
59 # include <sys/mman.h> 60 # include <sys/types.h> 61 # include <sys/stat.h> 62 # 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,
size_t count)
93 return ::_read(fd, buffer, count);
96 inline int raw_write(
int fd,
const void * buffer,
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,
size_t count)
134 return ::read(fd, buffer, count);
137 inline ssize_t
raw_write(
int fd,
const void * buffer,
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};
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)
215 #endif // __PCL_IO_LOW_LEVEL_IO__ int raw_ftruncate(int fd, off_t length)
This file defines compatibility wrappers for low level I/O functions.
int raw_open(const char *pathname, int flags, int mode)
int raw_fallocate(int fd, off_t length)
ssize_t raw_read(int fd, void *buffer, size_t count)
ssize_t raw_write(int fd, const void *buffer, size_t count)
off_t raw_lseek(int fd, off_t offset, int whence)