int WExec_FillBuffer(WExec* p) { int outcount,errcount; if (p->stdoutCount<WEXEC_BUFFERSIZE) { if (!_eof(p->handles[0])) { if ((outcount=read(p->handles[0],p->stdoutBuffer + p->stdoutCount,WEXEC_BUFFERSIZE-p->stdoutCount))>0) { p->stdoutCount+=outcount; } } } if (p->stderrCount<WEXEC_BUFFERSIZE) { if (!_eof(p->handles[0])) { if ((errcount=read(p->handles[2],p->stderrBuffer + p->stderrCount,WEXEC_BUFFERSIZE-p->stderrCount))>0) { p->stderrCount+=errcount; } } } if (p->stderrCount || p->stdoutCount) return p->stderrCount + p->stdoutCount; return 0; }
//! 重载写后台线程 DWORD WriteModel() { while ( Shell_.IsAlive() && bContinue_) { if (!_eof(Shell_.Read())) { while (!_eof(Shell_.Read()) && bContinue_) { BlockBuffer::InnerLock lock(&O_); int len = _read(Shell_.Read(), O_.GetFreePtr(256), 256); O_.Release(len); } } else Sleep(50); if (O_.Size()) { O_.Write("\x3"); BufferToPort(); } } return 0; }
bool AFile_Physical::_isNotEof() { if (mp_file) return (!_eof(m_fid)); else ATHROW(this, AException::NotOpen); }
int feof(FILE* stream) { _FILE* file = (_FILE*)stream; if (file == NULL) return EOF; // since we don't have buffering, just return low-level eof // TODO: when buffering is implemented, this will need more work return _eof(file->fd) == 1 ? 1 : 0; }
static int hb_gt_std_ReadKey( PHB_GT pGT, int iEventMask ) { PHB_GTSTD pGTSTD; int ch = 0; HB_TRACE(HB_TR_DEBUG, ("hb_gt_std_ReadKey(%p,%d)", pGT, iEventMask)); HB_SYMBOL_UNUSED( iEventMask ); pGTSTD = HB_GTSTD_GET( pGT ); #if defined( HB_OS_UNIX_COMPATIBLE ) || defined( __DJGPP__ ) { struct timeval tv; fd_set rfds; tv.tv_sec = 0; tv.tv_usec = 0; FD_ZERO( &rfds ); FD_SET( pGTSTD->hStdin, &rfds ); if( select( pGTSTD->hStdin + 1, &rfds, NULL, NULL, &tv ) > 0 ) { BYTE bChar; if( hb_fsRead( pGTSTD->hStdin, &bChar, 1 ) == 1 ) ch = pGTSTD->keyTransTbl[ bChar ]; } } #elif defined( _MSC_VER ) && !defined( HB_WINCE ) if( pGTSTD->fStdinConsole ) { if( _kbhit() ) { ch = _getch(); if( ( ch == 0 || ch == 224 ) && _kbhit() ) { /* It was a function key lead-in code, so read the actual function key and then offset it by 256 */ ch = _getch() + 256; } ch = hb_gt_dos_keyCodeTranslate( ch ); if( ch > 0 && ch <= 255 ) ch = pGTSTD->keyTransTbl[ ch ]; } } else if( !_eof( pGTSTD->hStdin ) ) { BYTE bChar; if( _read( pGTSTD->hStdin, &bChar, 1 ) == 1 ) ch = pGTSTD->keyTransTbl[ bChar ]; } #elif defined( HB_WIN32_IO ) if( !pGTSTD->fStdinConsole || WaitForSingleObject( ( HANDLE ) hb_fsGetOsHandle( pGTSTD->hStdin ), 0 ) == 0x0000 ) { BYTE bChar; if( hb_fsRead( pGTSTD->hStdin, &bChar, 1 ) == 1 ) ch = pGTSTD->keyTransTbl[ bChar ]; } #elif defined( __WATCOMC__ ) if( pGTSTD->fStdinConsole ) { if( kbhit() ) { ch = getch(); if( ( ch == 0 || ch == 224 ) && kbhit() ) { /* It was a function key lead-in code, so read the actual function key and then offset it by 256 */ ch = getch() + 256; } ch = hb_gt_dos_keyCodeTranslate( ch ); if( ch > 0 && ch <= 255 ) ch = pGTSTD->keyTransTbl[ ch ]; } } else if( !eof( pGTSTD->hStdin ) ) { BYTE bChar; if( read( pGTSTD->hStdin, &bChar, 1 ) == 1 ) ch = pGTSTD->keyTransTbl[ bChar ]; } #else { int TODO; /* TODO: */ } #endif return ch; }
int SMADFiler::eof(){ return _eof(handle); }
static int hb_gt_std_ReadKey( PHB_GT pGT, int iEventMask ) { PHB_GTSTD pGTSTD; int ch = 0; HB_TRACE( HB_TR_DEBUG, ( "hb_gt_std_ReadKey(%p,%d)", pGT, iEventMask ) ); HB_SYMBOL_UNUSED( iEventMask ); pGTSTD = HB_GTSTD_GET( pGT ); #if defined( HB_HAS_TERMIOS ) { struct timeval tv; fd_set rfds; tv.tv_sec = 0; tv.tv_usec = 0; FD_ZERO( &rfds ); FD_SET( pGTSTD->hStdin, &rfds ); if( select( pGTSTD->hStdin + 1, &rfds, NULL, NULL, &tv ) > 0 ) { HB_BYTE bChar; if( hb_fsRead( pGTSTD->hStdin, &bChar, 1 ) == 1 ) ch = bChar; } } #elif defined( _MSC_VER ) && ! defined( HB_OS_WIN_CE ) if( pGTSTD->fStdinConsole ) { if( _kbhit() ) { ch = _getch(); if( ( ch == 0 || ch == 224 ) && _kbhit() ) { /* It was a function key lead-in code, so read the actual function key and then offset it by 256 */ ch = _getch() + 256; } ch = hb_gt_dos_keyCodeTranslate( ch ); } } else if( ! _eof( ( int ) pGTSTD->hStdin ) ) { HB_BYTE bChar; if( _read( ( int ) pGTSTD->hStdin, &bChar, 1 ) == 1 ) ch = bChar; } #elif defined( HB_OS_WIN ) if( ! pGTSTD->fStdinConsole ) { HB_BYTE bChar; if( hb_fsRead( pGTSTD->hStdin, &bChar, 1 ) == 1 ) ch = bChar; } else if( WaitForSingleObject( ( HANDLE ) hb_fsGetOsHandle( pGTSTD->hStdin ), 0 ) == WAIT_OBJECT_0 ) { #if defined( HB_OS_WIN_CE ) HB_BYTE bChar; if( hb_fsRead( pGTSTD->hStdin, &bChar, 1 ) == 1 ) ch = bChar; #else INPUT_RECORD ir; DWORD dwEvents; while( PeekConsoleInput( ( HANDLE ) hb_fsGetOsHandle( pGTSTD->hStdin ), &ir, 1, &dwEvents ) && dwEvents == 1 ) { if( ir.EventType == KEY_EVENT && ir.Event.KeyEvent.bKeyDown ) { HB_BYTE bChar; if( hb_fsRead( pGTSTD->hStdin, &bChar, 1 ) == 1 ) ch = bChar; } else /* Remove from the input queue */ ReadConsoleInput( ( HANDLE ) hb_fsGetOsHandle( pGTSTD->hStdin ), &ir, 1, &dwEvents ); } #endif } #elif defined( __WATCOMC__ ) if( pGTSTD->fStdinConsole ) { if( kbhit() ) { ch = getch(); if( ( ch == 0 || ch == 224 ) && kbhit() ) { /* It was a function key lead-in code, so read the actual function key and then offset it by 256 */ ch = getch() + 256; } ch = hb_gt_dos_keyCodeTranslate( ch ); } } else if( ! eof( pGTSTD->hStdin ) ) { HB_BYTE bChar; if( read( pGTSTD->hStdin, &bChar, 1 ) == 1 ) ch = bChar; } #else { if( ! pGTSTD->fStdinConsole ) { HB_BYTE bChar; if( hb_fsRead( pGTSTD->hStdin, &bChar, 1 ) == 1 ) ch = bChar; } else { int iTODO; /* TODO: */ } } #endif if( ch ) { int u = HB_GTSELF_KEYTRANS( pGT, ch ); if( u ) ch = HB_INKEY_NEW_UNICODE( u ); } return ch; }
void dialogEditor_dataitem::LoadDataFile() { CString sError; int fh = 0; unsigned char cRead = 0; unsigned char cChecksum = 0; unsigned char cStorage[1024]; LPSTRUCT_LIVEBITITEM lpDataItem = NULL; int iLoop = 0; // Live Data File Format // 1 bytes [Version Length] // x bytes [Version] // 1 bytes [Version Checksum] // [..] // 1 bytes [Byte] // 1 bytes [Bit] // 1 bytes [Name Length] // x bytes [Name] // 4 bytes [Address High] // 4 bytes [Address Low] // 1 bytes [Type] // 2 bytes [Operand Addition] // 2 bytes [Operand Subtract] // 2 bytes [Operand Multiplier] // 2 bytes [Operand Divisor] // 2 bytes [Decimals] // 1 bytes [Unit Length] // x bytes [Unit] // 2 bytes [Description Length] // x bytes [Description] // 1 bytes [Checksum] // [..] BrowseForFile(&sError,"Select the Data Item Data File",OFN_FILEMUSTEXIST); if((fh = _open(sError,_O_BINARY | _O_RDONLY,_S_IREAD)) == -1) return; _lseek(fh,0,SEEK_SET); _read(fh,&cRead,1); _read(fh,&cStorage[0],cRead); cStorage[cRead] = '\0'; sVersion = cStorage; _read(fh,&cRead,1); while(!_eof(fh)) { if((lpDataItem = new STRUCT_LIVEBITITEM) == NULL) return; _read(fh,&lpDataItem->cByte,1); _read(fh,&lpDataItem->cBit,1); _read(fh,&lpDataItem->cLength_name,1); _read(fh,&cStorage,lpDataItem->cLength_name); cStorage[lpDataItem->cLength_name] = '\0'; lpDataItem->szName = (LPTSTR)malloc(lpDataItem->cLength_name + 1); memset(lpDataItem->szName,0,lpDataItem->cLength_name); strncpy(lpDataItem->szName,(LPCTSTR)&cStorage[0],lpDataItem->cLength_name + 1); _read(fh,&cStorage,4); memcpy(&lpDataItem->ulAddress_high,&cStorage,4); _read(fh,&cStorage,4); memcpy(&lpDataItem->ulAddress_low,&cStorage,4); _read(fh,&lpDataItem->cType,1); _read(fh,&cStorage,2); memcpy(&lpDataItem->usOperand_addition,&cStorage,2); _read(fh,&cStorage,2); memcpy(&lpDataItem->usOperand_subtract,&cStorage,2); _read(fh,&cStorage,2); memcpy(&lpDataItem->usOperand_multiplier,&cStorage,2); _read(fh,&cStorage,2); memcpy(&lpDataItem->usOperand_divisor,&cStorage,2); _read(fh,&cStorage,2); memcpy(&lpDataItem->usDecimals,&cStorage,2); _read(fh,&lpDataItem->cLength_unit,1); _read(fh,&cStorage,lpDataItem->cLength_unit); cStorage[lpDataItem->cLength_unit] = '\0'; lpDataItem->szUnit = (LPTSTR)malloc(lpDataItem->cLength_unit + 1); memset(lpDataItem->szUnit,0,lpDataItem->cLength_unit); strncpy(lpDataItem->szUnit,(LPCTSTR)&cStorage[0],lpDataItem->cLength_unit + 1); _read(fh,&lpDataItem->usLength_description,2); _read(fh,&cStorage,lpDataItem->usLength_description); cStorage[lpDataItem->usLength_description] = '\0'; lpDataItem->szDescription = (LPTSTR)malloc(lpDataItem->usLength_description + 1); memset(lpDataItem->szDescription,0,lpDataItem->usLength_description); strncpy(lpDataItem->szDescription,(LPCTSTR)&cStorage[0],lpDataItem->usLength_description + 1); _read(fh,&cRead,1); listDataItem.AddTail(lpDataItem); } _close(fh); pos = listDataItem.GetHeadPosition(); }
static void my_debug_output_i(FILE *stream, char *tmp, int cr) { static int trip = -1; int fd = fileno(stream); size_t wd = 0, w = strlen(tmp); int res; size_t reason, result; if (trip == -1) trip = trip_start; for (;;) { errno = 0; #ifndef NO_TRIP trip = !trip; #endif if (trip) { res = fwrite(tmp + wd, 1, w - wd, stream); } else { res = write(fd, tmp + wd, w - wd); } #ifdef DEBUG_INPUT if (logging) { if (!trip) #ifdef WIN32 fprintf(in, "res: %d, err: %d, eof?: %d, data: \"%s\"\n", res, errno, _eof(fd) ? 1 : 0, linearise(tmp + wd)); #else /* WIN32 */ fprintf(in, "res: %d, err: %d, data: \"%s\"\n", res, errno, linearise(tmp + wd)); #endif /* WIN32 */ else fprintf(in, "res: %d, err: %d, eof?: %d, data: \"%s\"\n", res, errno, feof(stream) ? 1 : 0, linearise(tmp + wd)); } #endif /* DEBUG_INPUT */ if (errno != 0) { D(("W: write (debug): res: %d, err: %d (%s), data: \"%s\"\n", res, errno, strerror(errno), linearise(tmp + wd))); #ifdef DEBUG_INPUT if (logging) fprintf(in, "res: %d, err: %d (%s), wd: %d, data: \"%s\"\n", res, errno, strerror(errno), wd, linearise(tmp + wd)); #endif /* DEBUG_INPUT */ } if (res > 0) { wd +=res; if (wd == w) { if (cr == 0) { return; } cr = 0; wd = 0; w = 1; tmp[0] = '\n'; tmp[1] = (char)0; } } if (errno != 0) { if (errno != EINTR && errno != EWOULDBLOCK && errno != EAGAIN) { D(("W: write: %d, error: %d (%s)\n", res, errno, strerror(errno))); return; } #ifdef DEBUG_OUTPUT if (logging) fprintf(in, "Entering select(), stream full\n"); #endif /* DEBUG_OUTPUT */ D(("W: Entering select(), current value: '%s'\n", tmp)); do { result = ssh_debug_wait_fd_writable(testpipe[1], 0, &reason); } while (result == -1 && reason == EINTR); } }
//iso_offset 32bit整数。能表示的数字最大约0x80000000,这个足够表示iso的,iso9660一般最多0x2??????? //如果换成64bit大整数,vb调用起来就略麻烦了,也暂时没必要。 //函数返回patch的字节数。如果错误返回负数,为各种可能的常量。 int WINAPI iso_patch_file(int iso_type, char *iso_file, int need_ecc_edc, int iso_offset, char *patch_file) { int fhISO, fhPatch; int sector_start; int sector_length; BYTE sector[2352]; // check that the supplied ISO offset is sane if (iso_offset <= 0) { return PATCH_ERR_OFFSET; } sector_start = iso_offset % 2352; if( sector_start < ISO9660_DATA_START[iso_type] || sector_start >= ISO9660_DATA_START[iso_type] + ISO9660_DATA_SIZE[iso_type] ) { 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; } sector_length = ISO9660_DATA_SIZE[iso_type] + ISO9660_DATA_START[iso_type] - sector_start; eccedc_init(); int total_patched_bytes = 0; int size_read; int nTmp; // nTmp is start of sector nTmp = iso_offset - (iso_offset % 2352); // seek to start of sector _lseek(fhISO, nTmp, SEEK_SET); // Until done reading bytes... for (;_eof(fhPatch)==0;) { // Read the current sector _read(fhISO,sector,2352); // Read the data out of the input file and into the sector size_read = _read(fhPatch, §or[sector_start], sector_length); if ((sector[0x12] & 8) == 0) { sector[0x12] = 8; sector[0x16] = 8; } if (need_ecc_edc != 0) { // Fixup ECC/EDC eccedc_generate(sector, iso_type); } _lseek(fhISO, -2352, SEEK_CUR); // Seek to beginning of sector _write(fhISO, sector, 2352); // Write the crap total_patched_bytes += size_read; // Update byte count sector_start = ISO9660_DATA_START[iso_type]; sector_length = ISO9660_DATA_SIZE[iso_type]; } _close(fhPatch); _close(fhISO); return total_patched_bytes; }
void CMainDlg::OnLoad() { CString sFile; int fhLabel = 0; unsigned char cRead; unsigned char cStorage[255]; LPSTRUCT_LABELITEM lpLabelItem = NULL; int iLoop; if(!BrowseForFile(&sFile)) return; if((fhLabel = _open(sFile,_O_BINARY | _O_RDONLY,_S_IREAD)) == -1) return; _lseek(fhLabel,0,SEEK_SET); _read(fhLabel,&cRead,1); _read(fhLabel,&cStorage,cRead); strncpy(sVersion.GetBufferSetLength(cRead),(LPCTSTR)&cStorage[0],cRead); sVersion.ReleaseBuffer(); _read(fhLabel,&cRead,1); while(!_eof(fhLabel)) { if((lpLabelItem = new STRUCT_LABELITEM) == NULL) return; _read(fhLabel,&lpLabelItem->cLength_id,1); lpLabelItem->szID = (LPTSTR)malloc(lpLabelItem->cLength_id + 1); memset(lpLabelItem->szID,0,lpLabelItem->cLength_id); _read(fhLabel,&cStorage,lpLabelItem->cLength_id); cStorage[lpLabelItem->cLength_id] = '\0'; strncpy(lpLabelItem->szID,(LPCTSTR)&cStorage[0],lpLabelItem->cLength_id + 1); _read(fhLabel,&lpLabelItem->cLength_label,1); lpLabelItem->szLabel = (LPTSTR)malloc(lpLabelItem->cLength_label + 1); memset(lpLabelItem->szLabel,0,lpLabelItem->cLength_label); _read(fhLabel,&cStorage,lpLabelItem->cLength_label); cStorage[lpLabelItem->cLength_label] = '\0'; strncpy(lpLabelItem->szLabel,(LPCTSTR)&cStorage[0],lpLabelItem->cLength_label + 1); // _read(fhLabel,&lpLabelItem->cLength_type,1); // lpLabelItem->szType = (LPTSTR)malloc(lpLabelItem->cLength_type + 1); // memset(lpLabelItem->szType,0,lpLabelItem->cLength_type); // _read(fhLabel,&cStorage,lpLabelItem->cLength_type); // cStorage[lpLabelItem->cLength_type] = '\0'; // strncpy(lpLabelItem->szType,(LPCTSTR)&cStorage[0],lpLabelItem->cLength_type + 1); _read(fhLabel,&lpLabelItem->cChecksum,1); listLabel.AddTail(lpLabelItem); } _close(fhLabel); pos = listLabel.GetHeadPosition(); lpLabelItem = (LPSTRUCT_LABELITEM)listLabel.GetAt(pos); for(iLoop = 0;iLoop < lpLabelItem->cLength_id;iLoop++) { sFile.Format("%02X ",(unsigned char)lpLabelItem->szID[iLoop]); sID += sFile; } sLabel = lpLabelItem->szLabel; // sType = lpLabelItem->szType; sChecksum = lpLabelItem->cChecksum; UpdateData(FALSE); usIndex++; sFile.Format("ecuExplorer Label Editor - %i of %i",usIndex,listLabel.GetCount()); SetWindowText(sFile); }