73 File::File() :m_fd(0),m_mode(OPEN_NO_MODE),m_lastError(0) {
77 if (this->m_mode != OPEN_NO_MODE) {
82 File::Status File::open(
const char* fileName, File::Mode mode) {
83 return this->open(fileName, mode,
true);
86 File::Status File::open(
const char* fileName, File::Mode mode,
bool include_excl) {
103 flags = O_WRONLY | O_CREAT | O_TRUNC;
105 case OPEN_SYNC_WRITE:
106 flags = O_WRONLY | O_CREAT | O_SYNC;
108 case OPEN_SYNC_DIRECT_WRITE:
109 flags = O_WRONLY | O_CREAT | O_DSYNC
116 flags = O_WRONLY | O_CREAT | O_TRUNC;
132 this->m_lastError = errno;
156 if (OPEN_NO_MODE == this->m_mode) {
172 fileStatus = DOESNT_EXIST;
195 if (OPEN_NO_MODE == this->m_mode) {
202 off_t act_off = ::lseek(this->m_fd,offset,whence);
206 if (act_off != offset) {
208 this->m_lastError = errno;
230 if (OPEN_NO_MODE == this->m_mode) {
240 while (maxIters > 0) {
242 ssize_t readSize = ::read(this->m_fd,
244 static_cast<char*
>(buffer)
250 if (readSize != size-accSize) {
252 if (-1 == readSize) {
261 this->m_lastError = errno;
264 }
else if (0 == readSize) {
269 if (not waitForFull) {
273 U8* charPtr = (
U8*)buffer;
274 charPtr = &charPtr[readSize];
275 buffer = (
void*)charPtr;
307 if (OPEN_NO_MODE == this->m_mode) {
314 while (maxIters > 0) {
317 static_cast<char*
>(
const_cast<void*
>(buffer))
322 if (-1 == writeSize) {
334 this->m_lastError = errno;
357 if (idx + chunkSize > totalSize) {
358 size = totalSize - idx;
364 totalSize = newBytesWritten;
369 sync_file_range(this->m_fd,
370 startPosition + newBytesWritten,
372 SYNC_FILE_RANGE_WRITE);
374 if (newBytesWritten) {
375 sync_file_range(this->m_fd,
376 startPosition + newBytesWritten - chunkSize,
378 SYNC_FILE_RANGE_WAIT_BEFORE
379 | SYNC_FILE_RANGE_WRITE
380 | SYNC_FILE_RANGE_WAIT_AFTER);
384 newBytesWritten += toWrite;
387 totalSize = newBytesWritten;
393 if (OPEN_NO_MODE == this->m_mode) {
399 if (-1 == fsync(this->m_fd)) {
413 void File::close(
void) {
414 (void)::close(this->m_fd);
415 this->m_mode = OPEN_NO_MODE;
422 const char* File::getLastErrorString(
void) {
423 return strerror(this->m_lastError);