unsigned LocalRead( sys_handle filehndl, void *ptr, unsigned len ) { tiny_ret_t ret; ret = TinyRead( filehndl, ptr, len ); if( TINY_ERROR( ret ) ) { StashErrCode( TINY_INFO( ret ), OP_LOCAL ); return( ERR_RETURN ); } return( TINY_INFO( ret ) ); }
void CheckPointRestore( void ) { dos_mem_block *chk; tiny_ret_t rc; tiny_handle_t hdl; rc = TinyOpen( ChkFile, TIO_READ ); if( TINY_ERROR( rc ) ) return; hdl = TINY_INFO( rc ); TinyRead( hdl, &chk, sizeof( chk ) ); TinyRead( hdl, chk, sizeof( *chk ) ); TinyRead( hdl, &chk, sizeof( chk ) ); while( TinyRead( hdl, chk, 0x8000 ) == 0x8000 ) { chk = MK_FP( FP_SEG( chk ) + 0x800, 0 ); } TinyClose( hdl ); Cleanup(); }
int __qread( int handle, void *buffer, unsigned len ) { #if defined( __NT__ ) DWORD amount_read; #elif defined(__OS2__) OS_UINT amount_read; APIRET rc; #else unsigned amount_read; tiny_ret_t rc; #endif __handle_check( handle, -1 ); #ifdef DEFAULT_WINDOWING if( _WindowsStdin != NULL ) { LPWDATA res; res = _WindowsIsWindowedHandle( handle ); if( res ) { int rt; rt = _WindowsStdin( res, buffer, len ); return( rt ); } } #endif #if defined(__NT__) if( !ReadFile( __getOSHandle( handle ), buffer, len, &amount_read, NULL ) ) { DWORD err; err = GetLastError(); __set_errno_dos( err ); if( err != ERROR_BROKEN_PIPE || amount_read != 0 ) { return( -1 ); } } #elif defined(__OS2__) rc = DosRead( handle, buffer, len, &amount_read ); if( rc ) { return( __set_errno_dos( rc ) ); } #else #if defined( __WINDOWS_386__ ) rc = __TinyRead( handle, buffer, len ); #else rc = TinyRead( handle, buffer, len ); #endif if( TINY_ERROR( rc ) ) { return( __set_errno_dos( TINY_INFO( rc ) ) ); } amount_read = TINY_LINFO( rc ); #endif return( amount_read ); }
unsigned QRead( f_handle file, void *buffer, unsigned len, char *name ) /****************************************************************************/ /* read into far memory */ { tiny_ret_t h; CheckBreak(); h = TinyRead( file, buffer, len ); if( TINY_ERROR( h ) ) { if( name != NULL ) { LnkMsg( ERR+MSG_IO_PROBLEM, "12", name, QErrMsg( TINY_INFO( h ) ) ); } else { return( -1 ); } } return( TINY_INFO(h) ); }
/* * chkRead - read checkpoint "file" */ static bool chkRead( void **buff ) { switch( isWhere ) { case ON_DISK: if( TinyRead( fileHandle, *buff, 0x8000 ) == 0x8000 ) { *buff = MK_FP( FP_SEG( *buff ) + 0x800, 0 ); return( true ); } return( false ); #ifndef NOEMS case IN_EMS: return( memBlockRead( EMSBlockRead, buff ) ); #endif #ifndef NOXMS case IN_XMS: return( memBlockRead( XMSBlockRead, buff ) ); #endif } } /* chkRead */
trap_retval ReqFile_read( void ) { tiny_ret_t rc; file_read_req *acc; file_read_ret *ret; char *buff; unsigned len; acc = GetInPtr( 0 ); ret = GetOutPtr( 0 ); buff = GetOutPtr( sizeof( *ret ) ); rc = TinyRead( acc->handle, buff, acc->len ); if( TINY_ERROR( rc ) ) { ret->err = TINY_INFO( rc ); len = 0; } else { ret->err = 0; len = TINY_INFO( rc ); } return( sizeof( *ret ) + len ); }
/* * chkRead - read checkpoint "file" */ static bool chkRead( void *buf ) { void **buff = buf; switch( isWhere ) { case ON_DISK: if( TinyRead( fileHandle, *buff, 0x8000 ) == 0x8000 ) { *buff = MK_FP( FP_SEG( *buff ) + 0x800, 0 ); return( TRUE ); } return( FALSE ); #ifndef NOEMS case IN_EMS: return( memBlockRead( EMSBlockRead, buff ) ); #endif #ifndef NOXMS case IN_XMS: return( memBlockRead( XMSBlockRead, buff ) ); #endif } return( FALSE ); // to quiet the compiler } /* chkRead */
static void AddModHandle( char *name, epsp_t *epsp ) /**************************************************/ { mod_t *mod; tiny_ret_t rc; int handle; object_record obj; unsigned_32 off; os2_flat_header os2_hdr; addr_off new_base; unsigned i; if( ModHandles == NULL ) { ModHandles = malloc( sizeof( mod_t ) ); } else { ModHandles = realloc( ModHandles, ( NumModHandles + 1 ) * sizeof( mod_t ) ); } mod = &ModHandles[NumModHandles]; ++NumModHandles; mod->epsp = epsp; mod->loaded = TRUE; mod->SegCount = 0; mod->ObjInfo = NULL; if( XVersion >= 0x404 ) { name = epsp->FileName; } rc = TinyOpen( name, TIO_READ ); if( TINY_ERROR( rc ) ) { return; } handle = TINY_INFO( rc ); TinySeek( handle, OS2_NE_OFFSET, SEEK_SET ); TinyRead( handle, &off, sizeof( off ) ); TinySeek( handle, off, SEEK_SET ); TinyRead( handle, &os2_hdr, sizeof( os2_hdr ) ); TinySeek( handle, os2_hdr.objtab_off + off, SEEK_SET ); mod->SegCount = os2_hdr.num_objects; mod->ObjInfo = malloc( os2_hdr.num_objects * sizeof( seg_t ) ); new_base = 0; for( i = 0; i < os2_hdr.num_objects; ++i ) { TinyRead( handle, &obj, sizeof( obj ) ); mod->ObjInfo[i].flags = obj.flags; mod->ObjInfo[i].base = obj.addr; mod->ObjInfo[i].size = obj.size; mod->ObjInfo[i].new_base = new_base; new_base += ALIGN4K( obj.size ); if( NumModHandles == 1 ) { // main executable if( obj.flags & OBJ_BIG ) { if( obj.flags & OBJ_EXECUTABLE ) { if( flatCode == FLAT_SEL ) { flatCode = ( mod->epsp->SegBase + i * 8 ) | 3; } } else { if( flatData == FLAT_SEL ) { flatData = ( mod->epsp->SegBase + i * 8 ) | 3; } } } } } TinyClose( handle ); }
static char *ReadInTrap( tiny_handle_t fh ) { dos_exe_header hdr; memptr relocbuff[NUM_BUFF_RELOCS]; unsigned relocnb; unsigned imagesize; unsigned hdrsize; rm_call_struct read; unsigned offset; if( TINY_ERROR( TinyRead( fh, &hdr, sizeof( hdr ) ) ) ) { return( TC_ERR_CANT_LOAD_TRAP ); } if( hdr.signature != DOS_SIGNATURE ) { return( TC_ERR_BAD_TRAP_FILE ); } hdrsize = hdr.hdr_size * 16; imagesize = (hdr.file_size * 0x200) - (-hdr.mod_size & 0x1ff) - hdrsize; TrapMem.dpmi_adr = DPMIAllocateDOSMemoryBlock( _NBPARAS( imagesize ) + hdr.min_16 ); if( TrapMem.segm.pm == 0 ) { return( TC_ERR_OUT_OF_DOS_MEMORY ); } TinySeek( fh, hdrsize, TIO_SEEK_SET ); memset( &read, 0, sizeof( read ) ); offset = 0; for( ;; ) { read.ss = RMData.segm.rm; read.sp = offsetof( rm_data, stack ) + STACK_SIZE; read.edx = offset; read.ebx = fh; read.ds = TrapMem.segm.rm; read.ecx = imagesize - offset; read.eax = 0x3f00; #if 1 relocnb = DPMISimulateRealModeInterrupt( 0x21, 0, 0, &read ); if( (read.flags & 1) || (unsigned_16)read.eax == 0 ) { return( TC_ERR_CANT_LOAD_TRAP ); } #else read.eax = TinyRead( fh, (void *)((TrapMem.segm.rm << 4) + offset), imagesize - offset ); if( (signed_32)read.eax < 0 ) { return( TC_ERR_CANT_LOAD_TRAP ); } #endif offset += (unsigned_16)read.eax; if( offset == imagesize ) break; } TinySeek( fh, hdr.reloc_offset, TIO_SEEK_SET ); for( relocnb = NUM_BUFF_RELOCS; hdr.num_relocs > 0; --hdr.num_relocs, ++relocnb ) { if( relocnb >= NUM_BUFF_RELOCS ) { if( TINY_ERROR( TinyRead( fh, relocbuff, sizeof( memptr ) * NUM_BUFF_RELOCS ) ) ) { return( TC_ERR_CANT_LOAD_TRAP ); } relocnb = 0; } *(addr_seg __far *)MK_PM( TrapMem.segm.rm + relocbuff[relocnb].s.segment, relocbuff[relocnb].s.offset ) += TrapMem.segm.rm; } return( NULL ); }
_WCRTLINK int read( int handle, void *buf, unsigned len ) #endif { unsigned read_len, total_len; unsigned reduce_idx, finish_idx; unsigned iomode_flags; char *buffer = buf; #if defined(__NT__) DWORD amount_read; BOOL rc; HANDLE h; #elif defined(__WARP__) ULONG amount_read; #elif defined(__OS2_286__) USHORT amount_read; #else unsigned amount_read; #endif #if !defined(__NT__) tiny_ret_t rc; #endif #ifdef DEFAULT_WINDOWING LPWDATA res; #endif __handle_check( handle, -1 ); __ChkTTYIOMode( handle ); iomode_flags = __GetIOMode( handle ); if( iomode_flags == 0 ) { #if defined( __WINDOWS__ ) || defined( __WINDOWS_386__ ) return( _lread( handle, buffer, len ) ); #else _RWD_errno = EBADF; return( -1 ); #endif } if( !(iomode_flags & _READ) ) { _RWD_errno = EACCES; /* changed from EBADF to EACCES 23-feb-89 */ return( -1 ); } #ifdef __NT__ h = __getOSHandle( handle ); #endif if( iomode_flags & _BINARY ) { /* if binary mode */ #ifdef DEFAULT_WINDOWING if( _WindowsStdin != 0 && (res = _WindowsIsWindowedHandle( handle )) != 0 ) { total_len = _WindowsStdin( res, buffer, len ); rc = 0; } else #endif { #if defined(__NT__) rc = ReadFile( h, buffer, len, &amount_read, NULL ); total_len = amount_read; if( !rc ) { if (GetLastError() == ERROR_BROKEN_PIPE) return total_len; return( __set_errno_nt() ); } #elif defined( __OS2__ ) rc = DosRead( handle, buffer, len, &amount_read ); total_len = amount_read; #else rc = TinyRead( handle, buffer, len ); total_len = TINY_LINFO( rc ); #endif } #if !defined(__NT__) if( TINY_ERROR( rc ) ) { return( __set_errno_dos( TINY_INFO( rc ) ) ); } #endif } else { _AccessFileH( handle ); total_len = 0; read_len = len; do { #ifdef DEFAULT_WINDOWING if( _WindowsStdin != 0 && (res = _WindowsIsWindowedHandle( handle )) != 0L ) { amount_read = _WindowsStdin( res, buffer, read_len ); rc = 0; } else #endif { #if defined(__NT__) rc = ReadFile( h, buffer, read_len, &amount_read, NULL ); if( !rc ) { _ReleaseFileH( handle ); if( GetLastError() == ERROR_BROKEN_PIPE ) return total_len; return( __set_errno_nt() ); } #elif defined( __OS2__ ) rc = DosRead( handle, buffer, read_len, &amount_read ); #else rc = TinyRead( handle, buffer, read_len ); amount_read = TINY_LINFO( rc ); #endif } #if !defined(__NT__) if( TINY_ERROR( rc ) ) { _ReleaseFileH( handle ); return( __set_errno_dos( TINY_INFO( rc ) ) ); } #endif if( amount_read == 0 ) { /* EOF */ break; } reduce_idx = 0; finish_idx = reduce_idx; for( ; reduce_idx < amount_read; ++reduce_idx ) { if( buffer[ reduce_idx ] == 0x1a ) { /* EOF */ __lseek( handle, ((long)reduce_idx - (long)amount_read)+1L, SEEK_CUR ); total_len += finish_idx; _ReleaseFileH( handle ); return( total_len ); } if( buffer[ reduce_idx ] != '\r' ) { buffer[ finish_idx++ ] = buffer[ reduce_idx ]; } } total_len += finish_idx; buffer += finish_idx; read_len -= finish_idx; if( iomode_flags & _ISTTY ) { break; /* 04-feb-88, FWC */ } } while( read_len != 0 ); _ReleaseFileH( handle ); } return( total_len ); }