virtual bool SetPos(dword pos){ if(pos > CACHE_SIZE){ LOG_RUN("C_file::Write SetPos overflow"); return false; } curr_pos = pos; return true; }
~C_file_write(){ if(hnd){ //flushing must be done before without error if(WriteFlush()){ //Fatal("Write error"); LOG_RUN("C_file::WriteFlush error"); } win::CloseHandle(hnd); } }
virtual C_file::E_WRITE_STATUS Write(const void *mem, dword len){ if(len){ if(curr_pos + len > CACHE_SIZE){ LOG_RUN("C_file::Write reg write overflow"); return C_file::WRITE_FAIL; } MemCpy(cache+curr_pos, mem, len); curr_pos += len; } return C_file::WRITE_OK; }
bool C_file::Open(const wchar *fname, dword open_flags){ Close(); #ifdef _DEBUG //make sure the filename doesn't contain 2 slashes for(int i=1; fname[i]; i++){ if(fname[i]=='\\' && fname[i-1]=='\\') return false; } #endif bool is_registry = (*fname == ':'); switch(open_flags&0xff){ case FILE_READ: { C_file_read_base *cr; if(!is_registry) cr = new C_file_read; else cr = new C_file_read_registry; imp = cr; if(!cr->Open(fname)){ Close(); return false; } } break; case FILE_WRITE: { if(open_flags&FILE_WRITE_CREATE_PATH) MakeSurePathExists(fname); C_file_write_base *cw; if(!is_registry) cw = new C_file_write; else cw = new C_file_write_registry; imp = cw; if(!cw->Open(fname, open_flags)){ Close(); return false; } } break; default: LOG_RUN("C_file: inv mode"); return false; } return true; }
virtual byte ReadByte(){ if(curr==top){ dword sz = ReadCache(); if(sz < sizeof(byte)){ //THROW(FILE_ERR_EOF); //Fatal("File", 1); LOG_RUN("C_file::ReadByte eof"); return 0; } top = base + sz; curr_pos += sz; } return *curr++; }
void DBMainLoop::ExitFlag(int) { continueFlag = false; LOG_RUN("Receive SIGUSR1, shutdown!"); }