WResFileSSize res_read( WResFileID fid, void * in_buff, WResFileSize size ) /*************************************************************************/ { RcBuffer *buff; size_t copy_bytes; size_t total_read; int i; WResFileSSize bytes_added; /* return value of FillRcBuffer */ if( hInstance.fid == fid ) { return( posix_read( WRES_FID2PH( fid ), in_buff, size ) ); } i = RcFindIndex( fid ); if( i >= RC_MAX_FILES ) { return( posix_read( WRES_FID2PH( fid ), in_buff, size ) ); } buff = RcFileList[i].Buffer; if( buff->IsDirty ) { if( FlushRcBuffer( fid, buff ) ) { return( -1 ); } } total_read = 0; while( size > 0 ) { if( buff->Count == 0 ) { bytes_added = FillRcBuffer( fid, buff ); if( bytes_added == -1 ) { return( bytes_added ); } else if( bytes_added == 0 ) { return( total_read ); } } copy_bytes = size; if( copy_bytes > buff->Count ) copy_bytes = buff->Count; memcpy( in_buff, buff->NextChar, copy_bytes ); buff->NextChar += copy_bytes; buff->Count -= copy_bytes; in_buff = (char *)in_buff + copy_bytes; size -= copy_bytes; total_read += copy_bytes; } return( total_read ); } /* RcRead */
static void openFiles( void ) { int objhdl; objhdl = open( ObjFileName, O_RDONLY | O_BINARY ); if( objhdl != -1 ) { if( ListFileName != NULL ) { OutputDest = open( ListFileName, O_WRONLY | O_CREAT | O_TRUNC, PMODE_RW ); if( OutputDest == -1 ) openError( ListFileName ); ChangePrintDest( OutputDest ); } objFileLen = filelength( objhdl ); if( objFileLen == 0 ) { LeaveProgram( RC_OKAY, WHERE_OBJ_ZERO_LEN ); } objFileBuf = MemAlloc( objFileLen ); objFilePos = 0; if( posix_read( objhdl, objFileBuf, objFileLen ) == -1 ) { openError( ObjFileName ); } close( objhdl ); } else { openError( ObjFileName ); } }
size_t readbytes( b_file *io, char *buff, size_t len ) //==================================================== { size_t bytes_read; size_t total; size_t amt; total = 0; amt = MAX_SYSIO_SIZE; while( len > 0 ) { if( amt > len ) amt = len; bytes_read = posix_read( io->handle, buff, amt ); if( bytes_read == READ_ERROR ) { FSetSysErr( io ); return( READ_ERROR ); } else if( bytes_read == 0 ) { if( total != 0 ) break; FSetEof( io ); return( READ_ERROR ); } io->phys_offset += (unsigned long)bytes_read; total += bytes_read; buff += bytes_read; len -= bytes_read; if( bytes_read < amt ) { break; } } return( total ); }
static int shell_readc(void) { char c; int result = posix_read(uart0_handler_pid, &c, 1); if (result != 1) { return -1; } return (unsigned char) c; }
size_t QRead( f_handle file, void *buffer, size_t len, const char *name ) /***********************************************************************/ { size_t ret; ret = posix_read( file, buffer, len ); if( ret == -1 ) { IOError( "io error processing ", name ); } return( ret ); }
size_t LocalRead( sys_handle sh, void *ptr, size_t len ) { ssize_t ret; ret = posix_read( SYSH2LH( sh ), ptr, len ); if( ret < 0 ) { StashErrCode( errno, OP_LOCAL ); return( ERR_RETURN ); } return( ret ); }
size_t QRead( int handle, void *buffer, size_t len ) /**************************************************/ { size_t result; result = posix_read( handle, buffer, len ); if( result == -1 ) { IOError( "problem reading file" ); } return( result ); }
char GetStdChar( void ) //======================== // Get a character from standard input. { char ch; #if defined( __WINDOWS__ ) ch = getche(); if( ch == CR ) return( LF ); #else if( posix_read( STDIN_FILENO, &ch, 1 ) < 0 ) return( NULLCHAR ); #if ! defined( __UNIX__ ) if( ch == CR ) { if( posix_read( STDIN_FILENO, &ch, 1 ) < 0 ) { return( NULLCHAR ); } } #endif #endif return( ch ); }
/* * Used by ORL. */ static void *obj_read( orl_file_id fid, size_t len ) /**************************************************/ { ListElem * newelem; newelem = AllocMem( sizeof( ListElem ) + len - 1 ); newelem->next = bufflist; bufflist = newelem; if( posix_read( ORL_FID2PH( fid ), newelem->buff, len ) != len ) { FreeMem( newelem ); return( NULL ); } return( newelem->buff ); }
static WResFileSSize FillRcBuffer( WResFileID fid, RcBuffer * buff ) /******************************************************************/ { buff->Count = posix_read( WRES_FID2PH( fid ), buff->Buffer, RC_BUFFER_SIZE ); if( buff->Count == -1 ) { buff->Count = 0; buff->BytesRead = 0; return( -1 ); } buff->BytesRead = buff->Count; buff->NextChar = buff->Buffer; return( buff->Count ); } /* FillRcBuffer */
int shell_readc() { char c = 0; posix_read(uart0_handler_pid, &c, 1); return c; }
WResFileSSize res_read( WResFileID fid, void *buf, WResFileSize size ) { return( posix_read( WRES_FID2PH( fid ), buf, size ) ); }
int uart0_readc(void) { char c = 0; posix_read(uart0_handler_pid, &c, 1); return c; }
static WResFileSSize wres_read( FILE *fp, void *buf, WResFileSize size ) { return( posix_read( FP2POSIX( fp ), buf, size ) ); }
static int shell_readc(void) { char c = 0; (void) posix_read(uart0_handler_pid, &c, 1); return c; }