extern void StartNewFile( char *fname ) /*************************************/ { cmdfilelist * newfile; unsigned long size; newfile = MemAlloc( sizeof( cmdfilelist ) ); newfile->name = fname; newfile->file = NIL_HANDLE; newfile->next = CmdFile; CmdFile = newfile; CmdFile->buffer = NULL; newfile->file = QOpenR( newfile->name ); size = QFileSize( newfile->file ); if( size < 65510 ) { // if can alloc a chunk big enough CmdFile->buffer = MemAlloc( size + 1 ); if( CmdFile->buffer != NULL ) { size = QRead( newfile->file, CmdFile->buffer, size, newfile->name ); *(CmdFile->buffer + size) = '\0'; CmdFile->where = MIDST; CmdFile->how = BUFFERED; CmdFile->current = CmdFile->buffer; } } if( CmdFile->buffer == NULL ) { // if couldn't buffer for some reason. CmdFile->where = ENDOFLINE; CmdFile->how = NONBUFFERED; CmdFile->buffer = MemAlloc( MAX_LINE + 1 );// have to have at least this CmdFile->current = CmdFile->buffer; // much RAM or death ensues. } }
bool CacheOpen( file_list *list ) /**************************************/ { infilelist *file; unsigned numblocks; char **cache; if( list == NULL ) return( TRUE ); file = list->file; if( file->flags & INSTAT_IOERR ) return( FALSE ); if( DoObjOpen( file ) ) { file->flags |= INSTAT_IN_USE; } else { file->flags |= INSTAT_IOERR; return( FALSE ); } if( file->len == 0 ) { file->len = QFileSize( file->handle ); if( file->len == 0 ) { LnkMsg( ERR+MSG_BAD_OBJECT, "s", file->name ); file->flags |= INSTAT_IOERR; return( FALSE ); } } if( !(file->flags & INSTAT_SET_CACHE) ) { if( LinkFlags & CACHE_FLAG ) { file->flags |= INSTAT_FULL_CACHE; } else if( LinkFlags & NOCACHE_FLAG ) { file->flags |= INSTAT_PAGE_CACHE; } else { if( file->flags & INSTAT_LIBRARY ) { file->flags |= INSTAT_PAGE_CACHE; } else { file->flags |= INSTAT_FULL_CACHE; } } } if( file->cache == NULL ) { if( file->flags & INSTAT_FULL_CACHE ) { _ChkAlloc( file->cache, file->len ); if( file->currpos != 0 ) { QLSeek( file->handle, 0, SEEK_SET, file->name ); } QRead( file->handle, file->cache, file->len, file->name ); file->currpos = file->len; } else { numblocks = NumCacheBlocks( file->len ); _Pass1Alloc( file->cache, numblocks * sizeof( char * ) ); cache = file->cache; while( numblocks > 0 ) { *cache = NULL; cache++; numblocks--; } } } return( TRUE ); }
static void WriteQNXResource( void ) /**********************************/ { unsigned long len; lmf_record rec; f_handle file; lmf_resource resource; void * buf; if( FmtData.resource != NULL ) { rec.reserved = 0; rec.spare = 0; rec.rec_type = LMF_RESOURCE_REC; memset( &resource, 0, sizeof( lmf_resource ) ); if( FmtData.res_name_only ) { file = QObjOpen( FmtData.resource ); if( file == NIL_FHANDLE ) { PrintIOError( WRN+MSG_CANT_OPEN_NO_REASON, "s", FmtData.resource ); return; } len = QFileSize( file ); if( len + sizeof(lmf_resource) > QNX_MAX_REC_SIZE ) { LnkMsg( WRN+MSG_RESOURCE_TOO_BIG, "s", FmtData.resource ); return; } _ChkAlloc( buf, len ); rec.data_nbytes = len + sizeof( lmf_resource ); WriteLoad( &rec, sizeof( lmf_record ) ); WriteLoad( &resource, sizeof( lmf_resource ) ); QRead( file, buf, len, FmtData.resource ); WriteLoad( buf, len ); _LnkFree( buf ); QClose( file, FmtData.resource ); } else { len = strlen( FmtData.resource ); FmtData.resource[len] = '\n'; len++; rec.data_nbytes = len + sizeof( lmf_resource ); WriteLoad( &rec, sizeof( lmf_record ) ); WriteLoad( &resource, sizeof( lmf_resource ) ); WriteLoad( FmtData.resource, len ); } } }