void Controler::_sigSlot() { _updateStatus("Signal notification received"); _sigNotifier->setEnabled(false); if( ::read(_sigFd[0], &_sigEmitter, sizeof(pid_t)) == -1) qFatal("read (1), in Controler::sigSlot"); if( ::read(_sigFd[0], &_sigCode, sizeof(SortTypes::SigCode)) == -1) qFatal("read (2), in Controler::sigSlot"); switch(_sigCode) { case SortTypes::RESULTS_SENT: _fetchResult(); _displaySortedList(); _tell(_sorter_pid, SortTypes::RESULTS_RECEIVED); break; default: qFatal("Controler::_sigSlot, unexpected signal"); } _sigNotifier->setEnabled(true); qDebug() << "Received SigCode " << SortUtility::SigCodeToQString(_sigCode) << "from (" << _sigEmitter << ")" << "\n"; }
unsigned int tell( int file ) { if ( file == -1 ) return 0; return _tell( file ); }
unsigned int tell( int file ) { if ( !file ) return 0; return _tell( file ); }
int WINAPI iso_patch_sector(char *iso_file, int iso_offset, char *patch_file) { int fhISO, fhPatch; //**** 初始化+合法性检查, 不合法返回错误 if (iso_offset <= 0) return PATCH_ERR_OFFSET; fhPatch = _open(patch_file, _O_BINARY | _O_RDONLY); if(fhPatch == -1){ return PATCH_ERR_FILE_PATCH;} fhISO = _open(iso_file, _O_BINARY | _O_RDWR); if(fhISO == -1){ _close(fhPatch); return PATCH_ERR_FILE_ISO;} //**** 写入 int total_patched_bytes = 0; static char buff[1024*1024]; int nBuff; _lseek(fhPatch, 0, SEEK_END); nBuff = _tell(fhPatch); _lseek(fhPatch, 0, SEEK_SET); if(nBuff > sizeof(buff)) return PATCH_ERR_DIRECT; _read(fhPatch,buff,nBuff); _lseek(fhISO, iso_offset, SEEK_SET); _write(fhISO, buff, nBuff); //写入修改后的扇区数据 total_patched_bytes += nBuff; //一个 patch 数据文件实际写入字节数计数 _close(fhPatch); _close(fhISO); return total_patched_bytes; }
unsigned long p_ftell(p_file *file) { if (file->binary&1) return _tell(file->fd); else /* broken in _O_TEXT mode, see p_fopen */ return ftell(file->fp); }
long FAR PASCAL FilGetPos (short sFilHdl) { #if (defined (W31)) /****************************************************/ return (FilSetPos (sFilHdl, 0L, SEEK_CUR)); #endif /*****************************************************************/ #if (defined (DOS)) /****************************************************/ return (_tell (sFilHdl)); #endif /*****************************************************************/ }
long ftell(FILE* stream) { _FILE* file = (_FILE*)stream; long pos; if (file == NULL) return -1L; pos = _tell(file->fd); return pos; }
int Papy3FTell (PAPY_FILE inFp, PapyLong *outFilePosP) { int err = 0; *outFilePosP = (long) _tell(inFp); if( *outFilePosP < 0 ) return -1; return err; } /* endof Papy3FTell */
int fgetpos(FILE* stream, fpos_t* pos) { _FILE* file = (_FILE*)stream; long _pos; if (file == NULL || pos == NULL) return -1; _pos = _tell(file->fd); if (_pos == -1L) return -1; *pos = (fpos_t)_pos; return 0; }
int __cdecl _zzip_encrypt_read ( int fh, void *buf, unsigned cnt ) { extern DWORD g_arrdwCrc32Table[256]; int pos = _tell(fh); int ret = _zzip_read(fh, buf, cnt); for(int i=0; i<ret; i++) { ((unsigned char*)buf)[i] ^= getZipEncryptXORKey(pos+i); } return ret; }
BOOL ActiveScriptImpl::LoadScriptCode(BSTR *ScriptText) { _bstr_t pth = fileName; int fp = _wopen(pth, _O_RDONLY|_O_BINARY); if( fp > 0 ) { _lseek(fp, 0, SEEK_END); int siz = _tell(fp); _lseek(fp, 0, SEEK_SET); char *pSt = new char[siz+1]; _read(fp, pSt, siz); _close(fp); pSt[siz] = 0; *ScriptText = _com_util::ConvertStringToBSTR(pSt); return true; } return false; }
DWORD LstSrcTxt (short sSrcHdl, LPSTR lpWrkBuf, WORD usBufSiz, DWORD ulTxtOff, IDXERRPRC lpMsgDsp) { unsigned uiErrCod; WORD usTxtLen; /********************************************************************/ /* Copy Text portion of file */ /********************************************************************/ if (ulTxtOff && (-1L != _lseek (sSrcHdl, ulTxtOff, SEEK_SET)) && (-1L != (ulTxtOff = _tell (sSrcHdl))) && (-1 != (usTxtLen = Rd_FilFwd (sSrcHdl, lpWrkBuf, min (usBufSiz - 1, VBSTXTMAX - 1), FIOENCNON, &uiErrCod)))) { lpWrkBuf[usTxtLen] = '\0'; lpMsgDsp ("%Fs\n", (LPSTR) lpWrkBuf); } else lpMsgDsp ("Txt Inactive\n"); /********************************************************************/ /********************************************************************/ return (0L); }
void main(void) { uint8_t inputProgramType; char *inputProgram; uint16_t inputProgramSize; ti_var_t programSlot; uint8_t selectedProgram, amountOfPrograms, res = VALID, type; unsigned int programDataSize, offset, totalSize; uint8_t beginList, amountOfProgramsToDisplay; uint8_t relativeSelectedProgram; const char ICEheader[] = {tii, 0}; ti_var_t tempProg; char buf[30], *temp_name = "", var_name[9]; sk_key_t key = 0; void *search_pos; bool didCompile; // Install hooks ti_CloseAll(); if ((tempProg = ti_Open("ICEHOOKS", "r"))) { ti_SetArchiveStatus(true, tempProg); SetHooks(ti_GetDataPtr(tempProg)); } // Enable lowercase asm("ld iy, 0D00080h"); asm("set 3, (iy+024h)"); // check if a program was used as input ti_CloseAll(); ice.usingInputProgram = false; inputProgram = os_RclAns(&inputProgramType); if (inputProgram && inputProgramType == TI_STRING_TYPE && inputProgram[2] == tProg && (inputProgramSize = *(uint16_t*)inputProgram) < 10) { memset(var_name, 0, sizeof var_name); memcpy(var_name, inputProgram + 3, inputProgramSize - 1); programSlot = ti_OpenVar(var_name, "r", TI_PRGM_TYPE); if (programSlot) { ice.usingInputProgram = true; } } // Yay, GUI! :) displayMainScreen: gfx_Begin(); gfx_SetColor(189); gfx_FillRectangle_NoClip(0, 0, 320, 10); gfx_SetColor(0); gfx_SetTextFGColor(0); gfx_HorizLine_NoClip(0, 10, 320); gfx_PrintStringXY(infoStr, 12, 1); // Get all the programs that start with the [i] token selectedProgram = 0; didCompile = false; ti_CloseAll(); if (ice.usingInputProgram) { goto compile_program; } search_pos = NULL; while ((temp_name = ti_DetectAny(&search_pos, ICEheader, &type)) != NULL) { if (type == TI_PRGM_TYPE || type == TI_PPRGM_TYPE) { // Hidden programs if ((uint8_t)(*temp_name) < 64) { *temp_name += 64; } // Save the program name inputPrograms[selectedProgram] = malloc(9); strcpy(inputPrograms[selectedProgram++], temp_name); } if (selectedProgram >= NUMBEROFPROGRAM) { break; } } amountOfPrograms = selectedProgram; beginList = 0; amountOfProgramsToDisplay = (amountOfPrograms > PROGRAMPERSCREEN ? PROGRAMPERSCREEN : amountOfPrograms); // Check if there are ICE programs if (!amountOfPrograms) { gfx_PrintStringXY("No programs found!", 10, 13); goto stop; } // Display all the sorted programs qsort(inputPrograms, amountOfPrograms, sizeof(char *), myCompare); displayProgramList(beginList, amountOfProgramsToDisplay); // Display buttons gfx_PrintStringXY("Build", 4, 232); printButton(1); gfx_PrintStringXY("Debug", 66, 232); printButton(65); gfx_PrintStringXY("Quit", 285, 232); printButton(279); gfx_SetColor(0); // Select a program selectedProgram = 1; relativeSelectedProgram = 1; while ((key = os_GetCSC()) != sk_Enter && key != sk_2nd && key != sk_Yequ && key != sk_Window) { uint8_t selectionOffset = relativeSelectedProgram * 10 + 3; gfx_PrintStringXY(">", 1, selectionOffset); if (key) { gfx_SetColor(255); gfx_FillRectangle_NoClip(1, selectionOffset, 8, 8); // Stop and quit if (key == sk_Clear || key == sk_Graph) { goto err; } // Select the next program if (key == sk_Down) { if (selectedProgram != amountOfPrograms) { selectedProgram++; relativeSelectedProgram++; if (relativeSelectedProgram > PROGRAMPERSCREEN) { clearProgramList(); relativeSelectedProgram--; beginList++; displayProgramList(beginList, amountOfProgramsToDisplay); } } else { clearProgramList(); selectedProgram = 1; relativeSelectedProgram = 1; beginList = 0; displayProgramList(beginList, amountOfProgramsToDisplay); } } // Select the previous program if (key == sk_Up) { if (selectedProgram != 1) { selectedProgram--; relativeSelectedProgram--; if(relativeSelectedProgram == 0) { clearProgramList(); relativeSelectedProgram++; beginList--; displayProgramList(beginList, amountOfProgramsToDisplay); } } else { clearProgramList(); selectedProgram = amountOfPrograms; relativeSelectedProgram = (amountOfPrograms > PROGRAMPERSCREEN ? PROGRAMPERSCREEN : amountOfPrograms); beginList = (selectedProgram >= PROGRAMPERSCREEN ? selectedProgram - PROGRAMPERSCREEN : 0); displayProgramList(beginList, amountOfProgramsToDisplay); } } } } // Set some vars strcpy(var_name, inputPrograms[selectedProgram - 1]); for (selectedProgram = 0; selectedProgram < amountOfPrograms; selectedProgram++) { free(inputPrograms[selectedProgram]); } compile_program: // Erase screen gfx_SetColor(255); gfx_FillRectangle_NoClip(0, 11, 320, 210); gfx_FillRectangle_NoClip(0, 220, 270, 20); didCompile = true; memset(&ice, 0, sizeof ice); memset(&expr, 0, sizeof expr); memset(®, 0, sizeof reg); memset(&prescan, 0, sizeof prescan); memset(&debug, 0, sizeof debug); // Output debug appvar if (key == sk_Window) { ice.debug = true; } gfx_SetTextXY(1, 12); displayMessageLineScroll("Prescanning..."); displayLoadingBarFrame(); ice.inPrgm = _open(var_name); _seek(0, SEEK_END, ice.inPrgm); ice.programLength = _tell(ice.inPrgm); ice.programData = (uint8_t*)0xD52C00; ice.programPtr = ice.programData; ice.programDataData = ice.programData + 0xFFFF; ice.programDataPtr = ice.programDataData; // Get the name/icon/description _rewind(ice.inPrgm); if ((res = getNameIconDescription()) != VALID) { displayError(res); goto stop; } // Open debug appvar to store things to sprintf(buf, "%.5sDBG", ice.outName); debug.dbgPrgm = ti_Open(buf, "w"); if (ice.debug) { if (!debug.dbgPrgm) { displayError(E_NO_DBG_FILE); goto stop; } // Write version bytes to debug appvar ti_PutC(DEBUG_VERSION_MAJOR, debug.dbgPrgm); ti_PutC(DEBUG_VERSION_MINOR, debug.dbgPrgm); // Write amount of programs to debug appvar ti_PutC(0, debug.dbgPrgm); } else if (debug.dbgPrgm) { ti_Delete(buf); } // Prescan the program and output the header preScanProgram(); if ((res = parsePrescan()) != VALID) { displayError(res); goto stop; } if (prescan.amountOfVariablesUsed > 84) { gfx_SetTextFGColor(224); sprintf(buf, "Too much variables used: %d", prescan.amountOfVariablesUsed); displayMessageLineScroll(buf); didCompile = false; goto stop; } // Allow hidden programs from Cesium if (*var_name < 64) { *var_name += 64; } sprintf(buf, "Compiling program %s...", var_name); displayMessageLineScroll(buf); // Create or empty the output program if parsing succeeded if ((res = parseProgram()) == VALID) { unsigned int previousSize = 0; // Get the sizes of both stacks ice.programSize = (uintptr_t)ice.programPtr - (uintptr_t)ice.programData; programDataSize = (uintptr_t)ice.programDataData - (uintptr_t)ice.programDataPtr; // Change the pointers to the data as well, but first calculate the offset offset = PRGM_START + ice.programSize - (uintptr_t)ice.programDataPtr; while (ice.dataOffsetElements--) { unsigned int *tempDataOffsetStackPtr = ice.dataOffsetStack[ice.dataOffsetElements]; *tempDataOffsetStackPtr += offset; } totalSize = ice.programSize + programDataSize + 3; // Export the program ice.outPrgm = _open(ice.outName); if (ice.outPrgm) { // This program already exists if ((uint8_t)ti_GetC(ice.outPrgm) != 0xEF || (uint8_t)ti_GetC(ice.outPrgm) != 0x7B) { gfx_SetTextFGColor(224); displayMessageLineScroll("Output program already exists!"); displayMessageLineScroll("Delete program to continue."); didCompile = false; goto stop; } previousSize = ti_GetSize(ice.outPrgm); ti_Close(ice.outPrgm); } ice.outPrgm = _new(ice.outName); if (!ice.outPrgm) { displayMessageLineScroll("Failed to open output file"); goto stop; } // Write ASM header ti_PutC(tExtTok, ice.outPrgm); ti_PutC(tAsm84CeCmp, ice.outPrgm); // Write ICE header to be recognized by Cesium ti_PutC(0x7F, ice.outPrgm); // Write the header, main program, and data to output :D ti_Write(ice.programData, ice.programSize, 1, ice.outPrgm); if (programDataSize) ti_Write(ice.programDataPtr, programDataSize, 1, ice.outPrgm); _rewind(ice.outPrgm); // Write final CRC to debug program, as well as the ending line of the first program and the amount of total programs if (ice.debug) { uint16_t CRC; CRC = GetCRC(ti_GetDataPtr(ice.outPrgm), ti_GetSize(ice.outPrgm)); WriteWordToDebugProg(CRC); ti_Seek(3 + offsetof(debug_prog_t, endingLine), SEEK_SET, debug.dbgPrgm); WriteWordToDebugProg(debug.currentLine); ti_Seek(2, SEEK_SET, debug.dbgPrgm); ti_PutC(debug.amountOfPrograms + 1, debug.dbgPrgm); // +1 because the main program starts at 0 } // Yep, we are really done! gfx_SetTextFGColor(4); displayMessageLineScroll("Successfully compiled!"); if (ice.debug) { displayMessageLineScroll("Successfully exported debug appvar"); } // Skip line displayMessageLineScroll(" "); // Display the size gfx_SetTextFGColor(0); sprintf(buf, "Output size: %u bytes", totalSize); displayMessageLineScroll(buf); if (previousSize) { sprintf(buf, "Previous size: %u bytes", previousSize); displayMessageLineScroll(buf); } sprintf(buf, "Output program: %s", ice.outName); displayMessageLineScroll(buf); } else if (res != W_VALID) { displayError(res); } stop: gfx_SetTextFGColor(0); if (didCompile) { if (res == VALID) { gfx_PrintStringXY("Run", 9, 232); printButton(1); } else if (!ti_IsArchived(ice.inPrgm)) { gfx_PrintStringXY("Goto", 222, 232); printButton(217); } gfx_PrintStringXY("Back", 70, 232); printButton(65); gfx_PrintStringXY("Quit", 285, 232); printButton(279); } while (!(key = os_GetCSC())); err: gfx_End(); if (key != sk_Graph && didCompile) { if (key == sk_Yequ && res == VALID) { RunPrgm(ice.outName); } if (key == sk_Window) { // Erase screen gfx_SetColor(255); gfx_FillRectangle_NoClip(0, 11, 320, 229); goto displayMainScreen; } if (key == sk_Trace && res != VALID && !ti_IsArchived(ice.inPrgm)) { char buf[9]; ti_GetName(buf, ice.inPrgm); GotoEditor(buf, ti_Tell(ice.inPrgm) - 1); } } ti_CloseAll(); }
int MrRipper::GetFiles(struct PluginPanelItem *PanelItem, int ItemsNumber, int Move, char *DestPath, int OpMode) { TSaveScreen SS; DWORD StartTime=GetTickCount(); BOOL WaitMessage=FALSE; double Progress1, Progress2; long FullSize,CurSize, ProcessedBytes; int Owervrite = 0; char MyDestPath[MAX_PATH]; char MyDestFile[MAX_PATH]; if (!OpMode & OPM_SILENT){ if (!DestDirPrompt(DestPath)) return -2; } if ((strlen(DestPath)==3)&& (DestPath[1]==':')&& (DestPath[2]=='\\')) DestPath[2] = 0; GetCurrentDirectory(MAX_PATH, MyDestPath); if (!SetCurrentDirectory(DestPath)) return FALSE; SetCurrentDirectory(MyDestPath); FormatFinder FF(PluginPath); for (int i = 0; i<FF.GetFormatCount(); i++) for (int j = 0; j<FF.GetnKnownFormats(i); j++) FF.SetActiveOpt(i, j, GetRegKey(HKEY_CURRENT_USER,"",FF.GetRegPath(i, j), 1)); MakeCopyList(PanelItem, ItemsNumber); int f1, f2; int readed, pos, endpos, getret; if (!bPluginManager){ FullSize = 0; for (int I = 0; I < copyfiles.size(); I++) FullSize += copyfiles[I].FileSize; ProcessedBytes = 0; for (I = 0; I < copyfiles.size(); I++){ if (copyfiles[I].FileName[strlen(copyfiles[I].FileName)-1]=='\\'){ char *c = my_substr(copyfiles[I].FileName, 0, strlen(copyfiles[I].FileName)-1); FSF.sprintf(MyDestPath, "%s\\%s", DestPath, c); my_free(c); CreateDirectory(MyDestPath, NULL); } else { char *d = ExtractPath(copyfiles[I].FileName); if (strlen(d)>0) FSF.sprintf(MyDestPath, "%s\\%s", DestPath, d); else strcpy(MyDestPath, DestPath); my_free(d); d = ExtractName(copyfiles[I].FileName); FSF.sprintf(MyDestFile, "%s", d); my_free(d); char c[MAX_PATH]; FSF.sprintf(c, "%s\\%s", MyDestPath, MyDestFile); f2 = _open(c, _O_RDONLY|_O_BINARY); if (f2!=-1) { _close(f2); if (Owervrite==3) continue; if (Owervrite == 0||Owervrite == 1) if (!OpMode & OPM_SILENT) Owervrite = OverwritePrompt(MyDestFile); if (Owervrite==-1) break; if (Owervrite==3||Owervrite==1) continue; } if (copyfiles[I].Fmt != FMT_DUMMY) if (FF.GetCanGetFile(copyfiles[I].Fmt, copyfiles[I].Plugin)&&ConvView){ getret = FF.GetFile(copyfiles[I].Plugin, copyfiles[I].Fmt, RipFileName, MyDestFile, MyDestPath, copyfiles[I].StartOffset, copyfiles[I].FileSize, copyfiles[I].UnpSize, OpMode & OPM_SILENT, copyfiles[I].UserData.Data); if (getret == 1){ ProcessedBytes += copyfiles[I].FileSize; WaitMessage=FALSE; if (!OpMode & OPM_SILENT){ if (GetTickCount()-StartTime>500){ if (CheckForKey(VK_ESCAPE)) break; Progress1 = 100.0; Progress2 = ProcessedBytes; Progress2 *= 100; Progress2 /= FullSize; char FileMsg[100], ProgressMsg1[100], ProgressMsg2[100]; FSF.sprintf(FileMsg,GetMsg(MExtracting), MyDestFile); FSF.sprintf(ProgressMsg1,GetMsg(MExtr1), Progress1); FSF.sprintf(ProgressMsg2,GetMsg(MExtr2), Progress2); const char *MsgItems[]={GetMsg(MExtraction),FileMsg, ProgressMsg1, ProgressMsg2}; Info.Message(Info.ModuleNumber,WaitMessage ? FMSG_LEFTALIGN|FMSG_KEEPBACKGROUND:FMSG_LEFTALIGN,NULL,MsgItems,sizeof(MsgItems)/sizeof(MsgItems[0]),0); WaitMessage=TRUE; } } continue; } if (getret == 2){ if (CheckForKey(VK_ESCAPE)) break; continue; } } FSF.sprintf(c, "%s\\%s", MyDestPath, MyDestFile); f1 = _open(RipFileName, _O_RDONLY|_O_BINARY); _lseek(f1,copyfiles[I].StartOffset,SEEK_SET); f2 = _open(c, _O_CREAT|_O_WRONLY|_O_BINARY); endpos = copyfiles[I].StartOffset+copyfiles[I].FileSize; CurSize = copyfiles[I].FileSize; pos = _tell(f1); while (pos<endpos){ if (!OpMode & OPM_SILENT){ if (GetTickCount()-StartTime>500){ if (CheckForKey(VK_ESCAPE)) break; Progress1 = (pos-copyfiles[I].StartOffset); Progress1 *= 100; Progress1 /= copyfiles[I].FileSize; Progress2 = ProcessedBytes; Progress2 *= 100; Progress2 /= FullSize; char FileMsg[100], ProgressMsg1[100], ProgressMsg2[100]; FSF.sprintf(FileMsg,GetMsg(MExtracting), MyDestFile); FSF.sprintf(ProgressMsg1,GetMsg(MExtr1), Progress1); FSF.sprintf(ProgressMsg2,GetMsg(MExtr2), Progress2); const char *MsgItems[]={GetMsg(MExtraction),FileMsg, ProgressMsg1, ProgressMsg2}; Info.Message(Info.ModuleNumber,WaitMessage ? FMSG_LEFTALIGN|FMSG_KEEPBACKGROUND:FMSG_LEFTALIGN,NULL,MsgItems,sizeof(MsgItems)/sizeof(MsgItems[0]),0); WaitMessage=TRUE; } } readed = _read(f1, buf, BUF_SIZE); pos = _tell(f1); if (pos > endpos) readed = readed - (pos - endpos); _write(f2, buf, readed); ProcessedBytes += readed; pos = _tell(f1); WaitMessage=FALSE; } _close(f2); _close(f1); SetFileAttributes(c, FILE_ATTRIBUTE_ARCHIVE); if (!OpMode & OPM_SILENT) if (CheckForKey(VK_ESCAPE)) break; } } Free_copyfiles(); return TRUE; } else { //For plugin manager ADDPLUGININFO *PI; for (int I = 0; I < copyfiles.size(); I++){ if (copyfiles[I].FileName[strlen(copyfiles[I].FileName)-1]=='\\'){ char *c = my_substr(copyfiles[I].FileName, 0, strlen(copyfiles[I].FileName)-1); FSF.sprintf(MyDestPath, "%s\\%s", DestPath, c); my_free(c); CreateDirectory(MyDestPath, NULL); } else { char *d = ExtractPath(copyfiles[I].FileName); if (strlen(d)>0) FSF.sprintf(MyDestPath, "%s\\%s", DestPath, d); else strcpy(MyDestPath, DestPath); my_free(d); d = ExtractName(copyfiles[I].FileName); FSF.sprintf(MyDestFile, "%s", d); my_free(d); char c[MAX_PATH]; FSF.sprintf(c, "%s\\%s", MyDestPath, MyDestFile); f2 = _open(c, _O_RDONLY|_O_BINARY); if (f2!=-1) { _close(f2); if (Owervrite==3) continue; if (Owervrite == 0||Owervrite == 1) if (!OpMode & OPM_SILENT) Owervrite = OverwritePrompt(MyDestFile); if (Owervrite==-1) break; if (Owervrite==3||Owervrite==1) continue; } FSF.sprintf(c, "%s\\%s", MyDestPath, MyDestFile); f2 = _open(c, _O_CREAT|_O_WRONLY|_O_BINARY); PI = (ADDPLUGININFO*)copyfiles[I].UserData.Data; FSF.sprintf((char*)buf, GetMsg(MInfoOptString), copyfiles[I].FileName); _write(f2, buf, lstrlen((char*)buf)+1); _write(f2, "\xD\xA\xD\xA", 4); FSF.sprintf((char*)buf, GetMsg(MInfoVer), copyfiles[I].Description); _write(f2, buf, lstrlen((char*)buf)+1); _write(f2, "\xD\xA", 2); char v[30]; Ver2Char(PI->RipVer, v); FSF.sprintf((char*)buf, GetMsg(MInfoRipVer), v); _write(f2, buf, lstrlen((char*)buf)+1); _write(f2, "\xD\xA\xD\xA", 4); FSF.sprintf((char*)buf, GetMsg(MInfoCopyright), PI->Copy); _write(f2, buf, lstrlen((char*)buf)+1); _write(f2, "\xD\xA", 2); FSF.sprintf((char*)buf, GetMsg(MInfoPath), PI->FilePath); _write(f2, buf, lstrlen((char*)buf)+1); _write(f2, "\xD\xA", 2); char *types[8] = {GetMsg(MInfoTypeGraph), GetMsg(MInfoTypeVideo), GetMsg(MInfoTypeSound), GetMsg(MInfoTypePack), GetMsg(MInfoTypeOther), GetMsg(MInfoTypeMusic), GetMsg(MInfoTypeText), GetMsg(MInfoTypeExe)}; FSF.sprintf((char*)buf, GetMsg(MInfoType), types[PI->Type]); _write(f2, buf, lstrlen((char*)buf)+1); _close(f2); SetFileAttributes(c, FILE_ATTRIBUTE_ARCHIVE); if (!OpMode & OPM_SILENT) if (CheckForKey(VK_ESCAPE)) break; } } Free_copyfiles(); //This for refuse reset selection if (!OpMode&OPM_SILENT) return -1; else return TRUE; } Free_copyfiles(); return TRUE; }
long FileSizeHandle(long handle) { return(_tell((int)handle - 1)); }
long SMADFiler::getpos(){ return _tell(handle); }
long tell(int fh) { return _tell(fh); }
/* * Constructor! */ STORAGE::DynamicMemoryMappedFile::DynamicMemoryMappedFile(const char* fname) : backingFilename(fname) { // If the backing file does not exist, we need to create it bool createInitial; int fd; bool exists = fileExists(backingFilename); fd = getFileDescriptor(backingFilename, !exists); isNewFile = !exists; createInitial = !exists; if (!exists) { createInitial = true; mapSize = INITIAL_SIZE; } else { // Read file size from the host filesystem _lseek(fd, 0L, SEEK_END); mapSize = _tell(fd); _lseek(fd, 0L, SEEK_SET); std::ostringstream os; os << mapSize; logEvent(EVENT, "Detected map size of " + os.str()); } fs = (char*)mmap((void*)NULL, mapSize, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (fs == MAP_FAILED) { logEvent(ERROR, "Could not map backing file"); _close(fd); shutdown(FAILURE); } if (createInitial) { logEvent(EVENT, "Creating initial file structure"); ftruncate(fd, mapSize); writeHeader(); } else { logEvent(EVENT, "Reading file structure"); // Read header, perform sanity check, remap. const char *header = readHeader(); if (!sanityCheck(header)) { // Uhoh... logEvent(ERROR, "Sanity check failed"); shutdown(FAILURE); } // Extract version and size. short recordedVersion; memcpy(&recordedVersion, header + sizeof(SANITY), sizeof(VERSION)); // If the version differs than there could be some compatibility issues... if (recordedVersion != VERSION) { // What do? logEvent(ERROR, "Version mismatch"); shutdown(FAILURE); } #if EXTRATESTING // Verify size matches recorded size from header. If mismatched then // potentially we lost data on the last write. size_t msize; memcpy(&msize, header + sizeof(SANITY) + sizeof(VERSION), sizeof(msize)); // mmap over the previous region if (msize != mapSize) { std::ostringstream os, os2; os << msize; os2 << mapSize; logEvent(EVENT, "File size mismatch, read " + os.str() + ", should be " + os2.str()); } #endif // Cleanup free((void*)header); } // We don't actually need the file descriptor any longer _close(fd); }