void INI_InsertSpace(int space) { // Since there is no good way to normally insert to or delete from a certain location in // a file, this function was added. It will insert (or delete) space bytes at the // current location. // note: negative count means delete char chunk[2048]; int len, file, start_pos, cur_pos; #ifdef _WIN32 file = _fileno(ini); #else // _WIN32 file = fileno(ini); #endif // _WIN32 start_pos = ftell(ini); fseek(ini,0,SEEK_END); // if adding, extend the file if (space > 0) #ifdef _WIN32 _chsize (file, _filelength(file)+space); #else // _WIN32 { int t1 = ftell(ini); fseek(ini, 0L, SEEK_END); int t2 = ftell(ini); fseek(ini, t1, SEEK_SET); ftruncate(file, t2+space); } #endif // _WIN32 while (1) { cur_pos = ftell(ini); len = cur_pos - start_pos; if (len == 0) break; if (len > 2048) len = 2048; fseek (ini,-len,SEEK_CUR); fread (chunk,1,len,ini); fseek (ini,-len+space,SEEK_CUR); fwrite (chunk,1,len,ini); fseek (ini,-len-space,SEEK_CUR); } // if deleted, make the file shorter if (space < 0) #ifdef _WIN32 _chsize (file, _filelength(file)+space); #else // _WIN32 { int t1 = ftell(ini); fseek(ini, 0L, SEEK_END); int t2 = ftell(ini); fseek(ini, t1, SEEK_SET); ftruncate(file, t2+space); } #endif // _WIN32 }
unsigned char * readFile(char *fname, int *len){ FILE *file; file = fopen(fname, "r"); if (file == NULL){ printf("Error of Reading\n"); } long temp_len; unsigned char * buf; temp_len = _filelength(_fileno(file)); printf("%d\n", temp_len); *len = (int)temp_len; buf = (unsigned char *)malloc(sizeof(*len)); fread(buf, 1, *len, file); printf("%d\n", *len); return buf; }
bool Debugger::SetBaseline() { #ifdef _WIN32 LPSTR script = nullptr; FILE *file = nullptr; int numChars = 0; HRESULT hr = S_OK; if (_wfopen_s(&file, HostConfigFlags::flags.dbgbaseline, _u("rb")) != 0) { Helpers::LogError(_u("opening baseline file '%s'"), HostConfigFlags::flags.dbgbaseline); } if(file != nullptr) { int fileSize = _filelength(_fileno(file)); if (fileSize <= MAX_BASELINE_SIZE) { script = new char[fileSize + 1]; numChars = static_cast<int>(fread(script, sizeof(script[0]), fileSize, file)); if (numChars == fileSize) { script[numChars] = '\0'; JsValueRef wideScriptRef; IfJsrtErrorFailLogAndRetFalse(ChakraRTInterface::JsCreateStringUtf8( (const uint8_t*)script, strlen(script), &wideScriptRef)); this->CallFunctionNoResult("SetBaseline", wideScriptRef); } else { Helpers::LogError(_u("failed to read from baseline file")); IfFailGo(E_FAIL); } } else { Helpers::LogError(_u("baseline file too large")); IfFailGo(E_FAIL); } } Error: if (script) { delete[] script; } if (file) { fclose(file); } return hr == S_OK; #else // xplat-todo: Implement this on Linux return false; #endif }
int image::open(char *inputFile) { int errNo; int fd; errNo = fopen_s(&fp, inputFile, "rb"); if (errNo != 0) return SDK_FAILURE; fd = _fileno(fp); fileLength = _filelength(fd); rawImageBuffer = (unsigned char*) malloc((size_t)fileLength); printInfo(1,"\ninfo : rawImageBuffer empty..filling rawImageBuffer\n"); if(!feof(fp)) { fread((void *)rawImageBuffer, sizeof(unsigned char),(size_t)fileLength, fp); curIndex = 0; if(ferror(fp)) { printError((ferror(fp)),"\nerror: could not read from file\n"); curIndex = 0; fileLength = 0; } if(feof(fp)) { printInfo((feof(fp)),"\ninfo : end of file occured during read\n"); return SDK_FAILURE; } } return SDK_SUCCESS; }
int TXTFAM::GetFileLength(PGLOBAL g) { char filename[_MAX_PATH]; int h; int len; PlugSetPath(filename, To_File, Tdbp->GetPath()); h= global_open(g, MSGID_OPEN_MODE_STRERROR, filename, _O_RDONLY); if (trace) htrc("GetFileLength: fn=%s h=%d\n", filename, h); if (h == -1) { if (errno != ENOENT) { if (trace) htrc("%s\n", g->Message); len = -1; } else { len = 0; // File does not exist yet g->Message[0]= '\0'; } } else { if ((len = _filelength(h)) < 0) sprintf(g->Message, MSG(FILELEN_ERROR), "_filelength", filename); if (Eof && len) len--; // Do not count the EOF character close(h); } // endif h return len; } // end of GetFileLength
ROWCELL *cppInitModernRow(ROWCELL ** tabAccess) { int fsize; int seq=0; ROWCELL * RowRoot=NULL; FILE * hFile; int i=0; if (!DBGetContactSettingByte(NULL,"ModernData","UseAdvancedRowLayout",0)) return NULL; tmplbuf=NULL; if (DBGetContactSettingByte(NULL,"ModernData","UseAdvancedRowLayout",0)==1) tmplbuf=DBGetStringA(NULL,"ModernData","RowTemplate"); if (tmplbuf) { rowParse(RowRoot, RowRoot, tmplbuf, i, seq,tabAccess); mir_free(tmplbuf); return RowRoot; } if (hFile = fopen("template.txt", "rb")) { fsize = _filelength(_fileno(hFile)); tmplbuf = (char*)malloc(fsize+1); ZeroMemory(tmplbuf, fsize+1); for (i=0; i<fsize; i++) tmplbuf[i] = getc(hFile); tmplbuf[i] = 0; i = 0; rowParse(RowRoot, RowRoot, tmplbuf, i, seq,tabAccess); DBWriteContactSettingString(NULL,"ModernData","RowTemplate",tmplbuf); free(tmplbuf); fclose(hFile); return RowRoot; } return NULL; }
static void cleanupDump( const char* _path ) { FILE* fp = fopen(_path, "rb"); const long fileSize = _filelength(_fileno(fp)); char* data = new char[fileSize]; fread(data, fileSize, 1, fp); fclose(fp); MINIDUMP_HEADER* header = (MINIDUMP_HEADER*)data; const bool signatureMatches = (header->Signature == MINIDUMP_SIGNATURE); if (signatureMatches) { delete[] data; return; } header = (MINIDUMP_HEADER*)(data + 8); if (header->Signature != MINIDUMP_SIGNATURE) { delete[] data; return; } fp = fopen(_path, "wb"); fwrite(data + 8, fileSize - 8, 1, fp); fclose(fp); }
void SecFile::SecClose() { if (!IsOpen()) return; StdFile::Flush(); if (!crash_b_) { #ifdef PEER_PC_CLIENT boost::uint32_t low_size = _filelength(_fileno(m_handle)); #else struct stat status; fstat(fileno(m_handle), &status); boost::uint32_t low_size = status.st_size; #endif assert(low_size == sec_content_count_); if (!only_read) { if (!DoSign()) { LOG4CPLUS_ERROR_LOG(logger_cfg_file, "SecFile::SecClose error: DoSign()"); } } } Close(); return; }
int LoadLubeFromFile(const char *pszName, PLUBEHEADER *ppLube) { int nSize, nRet = LUBE_FAIL; FILE *pFile; PLUBEHEADER pLube; pFile = fopen(pszName, "rb"); if (!pFile) { fprintf(stderr, "[ERROR] lube (0x0304 : Can't open file %s.\n", pszName); return LUBE_FAIL; } #ifdef _linux fseek(pFile, 0, SEEK_END); nSize = ftell(pFile); #else nSize = _filelength(pFile->_file); #endif pLube = (PLUBEHEADER)new char[nSize]; if (!pLube) { fprintf(stderr, "[ERROR] lube (0x0305 : Out of memory.\n"); goto ErrorExit; } fread(pLube, nSize, 1, pFile); nRet = RelocFlattedLube(pLube, nSize, ppLube); delete [] (char *)pLube; ErrorExit: fclose(pFile); return nRet; }
ROWCELL *cppInitModernRow(ROWCELL ** tabAccess) { int fsize; int seq = 0; ROWCELL * RowRoot = NULL; FILE * hFile; int i=0; if (!db_get_b(NULL,"ModernData","UseAdvancedRowLayout",SETTING_ROW_ADVANCEDLAYOUT_DEFAULT)) return NULL; tmplbuf = NULL; if ( db_get_b(NULL,"ModernData","UseAdvancedRowLayout",SETTING_ROW_ADVANCEDLAYOUT_DEFAULT) == 1) tmplbuf = db_get_sa(NULL,"ModernData","RowTemplate"); if (tmplbuf) { rowParse(RowRoot, RowRoot, tmplbuf, i, seq,tabAccess); mir_free(tmplbuf); return RowRoot; } if (hFile = fopen("template.txt", "rb")) { fsize = _filelength(_fileno(hFile)); tmplbuf = (char*)malloc(fsize+1); ZeroMemory(tmplbuf, fsize+1); for (i=0; i < fsize; i++) tmplbuf[i] = getc(hFile); tmplbuf[i] = 0; i=0; rowParse(RowRoot, RowRoot, tmplbuf, i, seq,tabAccess); db_set_s(NULL,"ModernData","RowTemplate",tmplbuf); free(tmplbuf); fclose(hFile); return RowRoot; } return NULL; }
bool ZmqEx::SendFile(void* socket, const char* filename) { FILE* file; fopen_s(&file, filename, "rb"); if ( file == NULL ) { assert(false); return false; } size_t length = _filelength( _fileno(file) ); int sendSize = zmq_send (socket, &length, sizeof(length), ZMQ_SNDMORE); assert(sendSize==sizeof(length)); char pbuffer[ZMQ_SEND_ONCE_MAX]; size_t nReadSize=0; while ( !feof(file) ) { nReadSize = fread(pbuffer, 1, ZMQ_SEND_ONCE_MAX, file); if ( nReadSize < ZMQ_SEND_ONCE_MAX ) break; sendSize = zmq_send (socket, pbuffer, nReadSize, ZMQ_SNDMORE); assert(sendSize==nReadSize); } sendSize = zmq_send (socket, pbuffer, nReadSize, 0); assert(sendSize==nReadSize); fclose(file); return true; }
std::vector< std::vector<int> > IdxFile::fromIdxFile(const char* filename) { FILE* answerFile = fopen(filename, "rb"); if (answerFile == NULL) { printf("idx file [%s] cannot be opened\n", filename); exit(-1); } int n = _filelength(_fileno(answerFile)); char* answerFileBuf = new char[n]; if (n != fread(answerFileBuf, sizeof(char), n, answerFile)) { printf("error when read idx file [%s]\n", filename); exit(-1); } fclose(answerFile); AnswerIndex* ai = (AnswerIndex*)answerFileBuf; int speechNum = ai->offset / sizeof(AnswerIndex); AnswerIndex* p = ai; std::vector< std::vector<int> > r(speechNum); for (int i = 0; i < speechNum; i++) { int* ansList = (int*)(answerFileBuf + p->offset); for (int j = 0; j < p->wordNum; j++) { r.at(i).push_back(ansList[j]); } p++; } return r; }
int Input::init (char* fn) { int nb; // Number of bytes read. filename = fn; filedesc = _open (filename, 0); // Open the file. if (filedesc < 0) // If open error. { printf ("File %s not found.\n", filename); return 0; } filesize = _filelength (filedesc); // Get filesize. input_start = new char [filesize+6]; // Get some RAM space. *input_start++ = '\n'; // Put <eol> at beginning. nb = _read (filedesc, input_start, filesize); // Read size bytes into buffer. if (nb <= 0) // If read error. { printf ("Read error on file %s.\n", filename); return 0; } input_end = input_start + nb; // Set end-of-buffer pointer. *input_end++ = EOL_CHAR; // Put end-of-line here. *input_end++ = EOF_CHAR; // Put first <eof> here. *input_end++ = EOF_CHAR; // Put second <eof> here. *input_end++ = EOL_CHAR; // Put end-of-line here. *input_end++ = 0; // Put zero byte here. _close (filedesc); // Close file. return 1; }
//+------------------------------------------------------------------+ //| Cut the file | //+------------------------------------------------------------------+ void CLogger::Cut(void) { FILE *in,*out; char *buf,*cp,tmp[256]; int len; //---- закроем файл на всякий случай m_sync.Lock(); FinalizeDay(); //---- откроем файл заново, проверим размер _snprintf(tmp,sizeof(tmp)-1,"%s.log",ExtProgramPath); if((in=fopen(tmp,"rb"))==NULL) { m_sync.Unlock(); return; } len=_filelength(_fileno(in)); if(len<300000) { fclose(in); m_sync.Unlock(); return; } //---- allocate 100 Kb for last messages and read them if((buf=(char*)malloc(102401))==NULL) { fclose(in); m_sync.Unlock(); return; } fseek(in,len-102400,SEEK_SET); fread(buf,102400,1,in); buf[102400]=0; fclose(in); //---- reopen log-file and write last messages if((out=fopen(tmp,"wb"))!=NULL) { if((cp=strstr(buf,"\n"))!=NULL) fwrite(cp+1,strlen(cp+1),1,out); fclose(out); } free(buf); //---- m_sync.Unlock(); }
static ULONG SizeOfFile(LPCSTR filepath) { FILE *pf = fopen(filepath, "rb"); ULONG size = _filelength(_fileno(pf)); fclose(pf); return size; }
VBoolean UUEXPORT UUVBClipFile( HWND owner, // New owner of clipboard const char *tfile) // Text file to put on clipboard { HGLOBAL mh = NULL; char _huge *mp = NULL; char wrk[1024]; FILE *inf = NULL; long fsize; unsigned int block; VBoolean rc = VBFALSE; if ((inf = fopen(tfile, "rb")) == NULL) return(VBFALSE); // Couldn't get the source file if ((fsize = _filelength(_fileno(inf))) <= 0 || // Couldn't open clipboard (mh = GlobalAlloc(GMEM_MOVEABLE, fsize + 10)) == NULL || // Couldn't allocate memory (mp = GlobalLock(mh)) == NULL) // No lock goto emex; while (fsize > 0) { block = (fsize > sizeof(wrk)) ? sizeof(wrk) : (unsigned int) fsize; if (fread(wrk, sizeof(char), block, inf) != block) goto emex; // Couldn't read the block _fmemcpy(mp, wrk, block); // Copy it mp += block; // Point to next memory dest fsize -= block; } *mp = EOS; // The last char is always a null GlobalUnlock(mh); mp = NULL; // Unlock the block so we can put it on the clipboard if (OpenClipboard(owner) == 0) goto emex; // Couldn't prep the clipboard if (EmptyClipboard() == 0 || // Couldn't empty it SetClipboardData(CF_TEXT, mh) == NULL) { // Couldn't set the new data CloseClipboard(); goto emex; } CloseClipboard(); rc = VBTRUE; // OK! emex: if (mp != NULL) GlobalUnlock(mh); // Have to unlock if (!rc && mh != NULL) GlobalFree(mh); // Error---free the memory fclose(inf); return(rc); }
sint32 filesize(FILE* fp) { #ifdef WIN32 return _filelength(_fileno(fp)); #else struct stat file_stat; fstat(fileno(fp), &file_stat); return (sint32) file_stat.st_size; #endif }
bool CLogFile::Open() { if (m_fp != NULL) return true; m_fp = _tfsopen(m_strFilePath, _T("a+b"), _SH_DENYWR); if (m_fp != NULL) { m_tStarted = time(NULL); m_uBytesWritten = _filelength(_fileno(m_fp)); if (m_uBytesWritten == 0) { if (m_eFileFormat == Unicode) { // write Unicode byte-order mark 0xFEFF fputwc(0xFEFF, m_fp); } else { ASSERT( m_eFileFormat == Utf8 ); ; // could write UTF-8 header.. } } else if (m_uBytesWritten >= sizeof(WORD)) { // check for Unicode byte-order mark 0xFEFF WORD wBOM; if (fread(&wBOM, sizeof(wBOM), 1, m_fp) == 1) { if (wBOM == 0xFEFF && m_eFileFormat == Unicode) { // log file already in Unicode format (void)fseek(m_fp, 0, SEEK_END); // actually not needed because file is opened in 'Append' mode.. } else if (wBOM != 0xFEFF && m_eFileFormat != Unicode) { // log file already in UTF-8 format (void)fseek(m_fp, 0, SEEK_END); // actually not needed because file is opened in 'Append' mode.. } else { // log file does not have the required format, create a new one (with the req. format) ASSERT( (m_eFileFormat==Unicode && wBOM!=0xFEFF) || (m_eFileFormat==Utf8 && wBOM==0xFEFF) ); ASSERT( !m_bInOpenCall ); if (!m_bInOpenCall) // just for safety { m_bInOpenCall = true; StartNewLogFile(); m_bInOpenCall = false; } } } } } return m_fp != NULL; }
int mesage_AddFieldBinary(lua_State* L) { CMessage* msg = cmessage_arg(L, "mesage_AddFieldBinary"); CString fldName = luaL_checkstring(L, 2); CString path = luaL_checkstring(L, 3); int err; char *description; int charsLen = ::MultiByteToWideChar(CP_UTF8, 0, path, lstrlen(path), NULL, 0); std::wstring characters(charsLen, '\0'); ::MultiByteToWideChar(CP_UTF8, 0, path, lstrlen(path), &characters[0], charsLen); int pf; char *b = NULL; err = _wsopen_s(&pf, characters.c_str(), _O_BINARY | _O_RDONLY, _SH_DENYWR, _S_IREAD); if (err) { description = "Open File error"; goto err; } DWORD l = _filelength(pf); b = new char[l]; if (l != _read(pf, b, l)) { err = -1; description = "Read File error"; goto err; } err = _close(pf); if (err) { description = "Close File error"; goto err; } { COleSafeArray arr; arr.Create(VT_UI1, 1, &l); for (DWORD i = 0; i < l; i++) { arr.PutElement((long*)&i, &b[i]); } msg->AddDatum(fldName, arr); } err: if (b) delete []b; lua_pushinteger(L, err); if (err) lua_pushstring(L, description); else lua_pushinteger(L, l); return 2; }
//void Conv2Bin() void Conv2Bin(char *ifname,char *ofname) { // char *ifname = "D:\\falcon4\\TOOLS\\tacref\\tacrefdb.txt"; // char *ofname = "D:\\falcon4\\TOOLS\\tacref\\tacrefdb.bin"; long bytesread; ifh = _open( ifname, _O_BINARY|_O_RDONLY ); if( ifh == -1 ) { printf("Error: can't open input file (%s)\n",ifname); return; // Error } //DrawText( gblhdc, "File Opened for Reading!", -1, &gblrect, DT_SINGLELINE); ofh = _open( ofname, _O_TRUNC|_O_CREAT|_O_BINARY|_O_WRONLY, _S_IREAD|_S_IWRITE ); if( ofh == -1 ) { if ( ifh ) _close ( ifh ); printf("Can't create output file (%s)\n",ofname); return; } // Get file length flen = _filelength( ifh ); /* Allocate space for dumping database file */ trdata = NULL; trdata = (char *) malloc( flen ); if( !trdata ) { // Error, printf( "Insufficient memory !\n" ); if ( ifh ) _close ( ifh ); if ( ofh ) _close ( ofh ); return; } // reads in the database file if (( bytesread = (long) _read( ifh, trdata, flen )) <= 0 ) { // Error, perror( "Problem reading file" ); if ( ifh ) _close ( ifh ); if ( ofh ) _close ( ofh ); if ( trdata ) { free( trdata ); trdata = NULL; } return; } startdata = trdata; endingdata = startdata+flen; trdata = SkipJunk( trdata ); startentity = trdata; InitVar(); // Conversion DoParse(); _close( ifh ); _close( ofh ); DrawText( gblhdc, "Both files are Closed ! ", -1, &gblrect, DT_SINGLELINE); free( startdata ); }
// strip out any ships tbl data not used in demo (ie entries without @ preceding name) void scramble_read_ships_tbl(char **text, int *text_len, FILE *fp) { char line[MAX_LINE_LEN+1]; char token_line[MAX_LINE_LEN+1]; char *dest; int line_len, discard_line = 1, keep_all_lines = 0, post_discard = 0; char seps[] = " ,\t\n"; char *token; *text_len = _filelength(fileno(fp)); *text = (char*)malloc(*text_len+1); dest = *text; while ( fgets(line, MAX_LINE_LEN, fp) != NULL ) { line_len = strlen(line); memcpy(token_line, line, line_len+1); if ( !keep_all_lines ) { token = strtok( token_line, seps ); if ( token ) { if ( !strnicmp("#End", token, 4) ) { keep_all_lines = 1; } else if ( !strnicmp("#Ship", token, 5) ) { discard_line = 0; post_discard = 1; } else if ( !strnicmp("$Name:", token, 6) ) { token = strtok( NULL, seps ); if ( token ) { if ( token[0] == '@' ) { discard_line = 0; } else { discard_line = 1; } } } } } if ( !discard_line || keep_all_lines ) { memcpy(dest, line, line_len); dest += line_len; } if ( post_discard ) { discard_line = 1; post_discard = 0; } } *text_len = dest - *text; }
uint64 FileSize(TFile *f) { #ifdef _WIN32 return (_filelength(*f)); #else struct stat fs; fstat(*f,&fs); return (fs.st_size); #endif }
int _tmain(int argc, _TCHAR* argv[]) { FILE* pFile=NULL; PBYTE PEImage=NULL; PBYTE pCodeData=NULL; DWORD baseAddress=0; unsigned int CodeDatSize=0; BYTE MajorLinkerVersion=0; PCHAR PEFileNam="..\\test.exe"; CHAR LogFileNam[MAX_PATH]; #pragma region 加载PE文件 fopen_s(&pFile,PEFileNam,"rb"); if(!pFile) { printf("Error:Can't open %s",PEFileNam); return 0; } const unsigned int fileLen=_filelength(_fileno(pFile)); PEImage=new BYTE[fileLen]; fread_s(PEImage,fileLen,fileLen,1,pFile); fclose(pFile); #pragma endregion #pragma region 解析PE文件 CPEInfo PEInfo; if(!PEInfo.Parse(PEImage)) return 0; pCodeData=PEInfo.GetCodeData(); CodeDatSize=PEInfo.GetCodeDataSize(); MajorLinkerVersion=PEInfo.GetMajorLinkerVersion(); baseAddress=PEInfo.GetBaseAddress(); #pragma endregion //初始化LibScanner,其中加载对于的flb文件 if(!InitLibScanner(MajorLinkerVersion)) return 0; #pragma region 调用反汇编引擎 strcpy_s(LogFileNam,MAX_PATH,PEFileNam); ModifySuffix(LogFileNam,".log"); fopen_s(&pLogFile,LogFileNam,"wb"); if(!pFile) { printf("Error:Can't open %s\n",PEFileNam); return 0; } PVDasm(pCodeData,CodeDatSize,baseAddress,pLogFile); fclose(pLogFile); #pragma endregion printf("PEFile %s Analysis Succeed!\n",PEFileNam); delete[] PEImage; return 0; }
bool file_handle_internal (LPCSTR file_name, u32 &size, int &file_handle) { if (open_internal(file_name, file_handle)) { Sleep (1); if (open_internal(file_name, file_handle)) return (false); } size = _filelength(file_handle); return (true); }
uint64_t FileSize(TFile *f) { #if defined( WIN32 ) && !defined( __BORLANDC__ ) return (_filelength(*f)); #else struct stat fs; fstat(*f,&fs); return (fs.st_size); #endif }
uint64_t FileSize(const TFile * const fileP) { #if MSVCRT return (_filelength(fileP->fd)); #else struct stat fs; fstat(fileP->fd, &fs); return (fs.st_size); #endif }
TUint32 HFile::GetLength(TText *aName) { TInt32 handle; if (HFile::Open(aName, &handle)==0) { TUint32 size = _filelength(handle); HFile::Close(handle); return size; } else return 0; }
/* load a file into memory */ BOOL Host_LoadFile(const char *Filename, unsigned char **pLocation, unsigned long *pLength) { FILE *fh; unsigned char *pData; *pLocation = NULL; *pLength = 0; if (Filename!=NULL) { if (strlen(Filename)!=0) { fh = fopen(Filename,"rb"); if (fh!=NULL) { int FileSize; #ifdef WIN32 int FNo; FNo = _fileno(fh); FileSize = _filelength(FNo); #else unsigned long CurrentPosition; CurrentPosition = ftell(fh); fseek(fh, 0, SEEK_END); FileSize = ftell(fh); fseek(fh, CurrentPosition, SEEK_SET); #endif if (FileSize!=0) { pData = (unsigned char *)malloc(FileSize); if (pData!=NULL) { fread(pData,1,FileSize,fh); *pLocation = pData; *pLength = FileSize; fclose(fh); return TRUE; } } fclose(fh); } } } return FALSE; }
// strip out any weapons tbl data not used in demo (ie entries without @ preceding name) void scramble_read_weapons_tbl(char **text, int *text_len, FILE *fp) { char line[MAX_LINE_LEN+1]; char token_line[MAX_LINE_LEN+1]; char *dest; int line_len, discard_line = 1, keep_all_lines = 0, post_discard = 0; char seps[] = " ,\t\n"; char *token = NULL; *text_len = _filelength(fileno(fp)); *text = (char*)malloc(*text_len+1); dest = *text; while ( fgets(line, MAX_LINE_LEN, fp) != NULL ) { line_len = strlen(line); memcpy(token_line, line, line_len+1); if ( !keep_all_lines ) { token = strtok( token_line, seps ); if ( token ) { if ( !strnicmp("#Countermeasures", token, 16) ) { keep_all_lines = 1; } else if ( !strnicmp("#End", token, 4) || !strnicmp("#Beam", token, 5) || !strnicmp("#Primary", token, 8) || !strnicmp("#Secondary", token, 10) ) { discard_line = 0; post_discard = 1; } else if ( !strnicmp("$Name:", token, 6) ) { discard_line = 1; token = strtok( NULL, seps ); if ( token ) { if ( token[0] == '@' ) { discard_line = 0; } } } } } if ( (token[0] != ';') && (!discard_line || keep_all_lines) ) { memcpy(dest, line, line_len); dest += line_len; } if ( post_discard ) { discard_line = 1; post_discard = 0; } } *text_len = dest - *text; }
void CSelectFilesOnCDDlg::LoadInfoFromDisk() { int i=0; long lFLength; int nHandle; char cFileName[MAX_PATH], cSta[8]; char *Buff; strcpy(cFileName, cDisk); strcat(cFileName,"README.TXT"); nHandle = open(cFileName, O_BINARY|O_RDONLY); lFLength = _filelength(nHandle); Buff = new char[lFLength+1]; if(read(nHandle, Buff, lFLength)>0) { Buff[lFLength-1] = 0; GetDlgItem(IDC_EDIT)->SetWindowText(Buff); } delete Buff; close(nHandle); strcpy(cFileName, cDisk); strcat(cFileName,"CONTENTS.TXT"); nHandle = open(cFileName, O_BINARY|O_RDONLY); lFLength = _filelength(nHandle); Buff = new char[lFLength+1]; if(read(nHandle, Buff, lFLength)>0) { Buff[lFLength-1] = 0; sscanf(Buff, "%s %d", cSta, &nRelease); Station=cSta; } close(nHandle); delete Buff; }