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
117 flags = O_WRONLY | O_CREAT | O_TRUNC;
136 this->m_lastError = errno;
160 if (OPEN_NO_MODE == this->m_mode) {
176 fileStatus = DOESNT_EXIST;
199 if (OPEN_NO_MODE == this->m_mode) {
206 off_t act_off = ::lseek(this->m_fd,offset,whence);
210 if (act_off != offset) {
212 this->m_lastError = errno;
234 if (OPEN_NO_MODE == this->m_mode) {
244 while (maxIters > 0) {
246 ssize_t readSize = ::read(this->m_fd,
248 static_cast<char*
>(buffer)
254 if (readSize != size-accSize) {
256 if (-1 == readSize) {
265 this->m_lastError = errno;
268 }
else if (0 == readSize) {
273 if (not waitForFull) {
277 U8* charPtr = (
U8*)buffer;
278 charPtr = &charPtr[readSize];
279 buffer = (
void*)charPtr;
311 if (OPEN_NO_MODE == this->m_mode) {
318 while (maxIters > 0) {
321 static_cast<char*
>(
const_cast<void*
>(buffer))
326 if (-1 == writeSize) {
338 this->m_lastError = errno;
361 if (idx + chunkSize > totalSize) {
362 size = totalSize - idx;
368 totalSize = newBytesWritten;
373 sync_file_range(this->m_fd,
374 startPosition + newBytesWritten,
376 SYNC_FILE_RANGE_WRITE);
378 if (newBytesWritten) {
379 sync_file_range(this->m_fd,
380 startPosition + newBytesWritten - chunkSize,
382 SYNC_FILE_RANGE_WAIT_BEFORE
383 | SYNC_FILE_RANGE_WRITE
384 | SYNC_FILE_RANGE_WAIT_AFTER);
388 newBytesWritten += toWrite;
391 totalSize = newBytesWritten;
397 if (OPEN_NO_MODE == this->m_mode) {
403 if (-1 == fsync(this->m_fd)) {
417 void File::close(
void) {
418 (void)::close(this->m_fd);
419 this->m_mode = OPEN_NO_MODE;
426 const char* File::getLastErrorString(
void) {
427 return strerror(this->m_lastError);