/* * WriteOS2ResTable * NB when an error occurs this function must return without altering errno */ extern RcStatus WriteOS2ResTable( WResFileID handle, OS2ResTable *restab, int *err_code ) /***************************************************************************************/ { RcStatus ret; uint_16 res_type; uint_16 res_id; int i; ret = RS_OK; for( i = 0; i < restab->num_res_segs && ret == RS_OK; i++ ) { res_type = restab->resources[i].res_type; res_id = restab->resources[i].res_id; if( RCWRITE( handle, &res_type, sizeof( uint_16 ) ) != sizeof( uint_16 ) ) { ret = RS_WRITE_ERROR; } else { if( RCWRITE( handle, &res_id, sizeof( uint_16 ) ) != sizeof( uint_16 ) ) { ret = RS_WRITE_ERROR; } } } *err_code = errno; if( restab->resources != NULL ) { RCFREE( restab->resources ); } return( ret ); } /* WriteOS2ResTable */
static bool ResOS2WriteHelpEntry( HelpTableEntryOS2 *currentry, WResFileID handle ) /**************************************************************************/ { if( RCWRITE( handle, currentry, sizeof( HelpTableEntryOS2 ) ) != sizeof( HelpTableEntryOS2 ) ) { WRES_ERROR( WRS_WRITE_FAILED ); return( true ); } return( false ); }
static bool ResOS2WriteMenuHeader( MenuHeaderOS2 *currhead, WResFileID handle ) /*********************************************************************/ { if( RCWRITE( handle, currhead, sizeof( MenuHeaderOS2 ) ) != sizeof( MenuHeaderOS2 ) ) { WRES_ERROR( WRS_WRITE_FAILED ); return( true ); } else { return( false ); } }
static bool ResOS2WriteDlgTemplate( char *tmpldata, int size, WResFileID handle ) /*******************************************************************************/ { if( RCWRITE( handle, tmpldata, size ) != size ) { WRES_ERROR( WRS_WRITE_FAILED ); return( true ); } else { return( false ); } }
int ResOS2WriteMenuHeader( MenuHeaderOS2 *currhead, WResFileID handle ) /*********************************************************************/ { int numwrote; numwrote = RCWRITE( handle, currhead, sizeof(MenuHeaderOS2) ); if( numwrote != sizeof(MenuHeaderOS2) ) { WRES_ERROR( WRS_WRITE_FAILED ); return( TRUE ); } else { return( FALSE ); } }
static CpSegRc copyOneSegment( const segment_record * inseg, segment_record * outseg, ExeFileInfo *inexe, ExeFileInfo *outexe, int old_shift_count, int new_shift_count, bool pad_end ) { CpSegRc ret; bool error; WResFileSSize numread; uint_16 numrelocs; long out_offset; long align_amount; uint_32 seg_len = 0L; char zero; zero = 0; error = false; ret = CPSEG_OK; /* check if this is a segment that has no image in the exe file */ if( inseg->address != 0 ) { /* align in the out file so that shift_count will be valid */ out_offset = RCTELL( outexe->Handle ); if( out_offset == -1 ) { error = true; RcError( ERR_WRITTING_FILE, outexe->name, strerror( errno ) ); } if( !error ) { align_amount = AlignAmount( out_offset, new_shift_count ); if( RCSEEK( outexe->Handle, align_amount, SEEK_CUR ) == -1 ) { error = true; RcError( ERR_WRITTING_FILE, outexe->name, strerror( errno ) ); } out_offset += align_amount; } /* move in the in file to the start of the segment */ if( !error ) { /* convert the address to a long before shifting it */ if( RCSEEK( inexe->Handle, (long)inseg->address << old_shift_count, SEEK_SET ) == -1 ) { error = true; RcError( ERR_READING_EXE, inexe->name, strerror( errno ) ); } } if( !error ) { if( inseg->size == 0 ) { seg_len = 0x10000L; } else { seg_len = inseg->size; } error = myCopyExeData( inexe, outexe, seg_len ); } if( (inseg->info & SEG_RELOC) && !error ) { /* read the number of relocation items */ numread = RCREAD( inexe->Handle, &numrelocs, sizeof(uint_16) ); if( numread != sizeof( uint_16 ) ) { error = true; if( RCIOERR( inexe->Handle, numread ) ) { RcError( ERR_READING_EXE, inexe->name, strerror( errno ) ); } else { RcError( ERR_UNEXPECTED_EOF, inexe->name ); } } else { if( RCWRITE( outexe->Handle, &numrelocs, sizeof(uint_16) ) != sizeof( uint_16 ) ) { error = true; RcError( ERR_WRITTING_FILE, outexe->name, strerror( errno ) ); } } /* copy the relocation information */ if( !error ) { error = myCopyExeData( inexe, outexe, numrelocs * OS_RELOC_ITEM_SIZE ); } if( numrelocs * OS_RELOC_ITEM_SIZE + seg_len > 0x10000L ) { ret = CPSEG_SEG_TOO_BIG; } } if( pad_end && ret != CPSEG_SEG_TOO_BIG && !error ) { align_amount = AlignAmount( RCTELL( outexe->Handle ), new_shift_count ); /* make sure there is room for the memory arena header */ if( align_amount < 16 ) { align_amount += 16; } if( RCSEEK( outexe->Handle, align_amount - 1, SEEK_CUR ) == -1 ) { error = true; RcError( ERR_WRITTING_FILE, outexe->name ); } else { /* write something out so if we have just seeked past the * end of the file the file's size will be adjusted * appropriately */ if( RCWRITE( outexe->Handle, &zero, 1 ) != 1 ) { error = true; RcError( ERR_WRITTING_FILE, outexe->name ); } } } } else { out_offset = 0; } /* copy the segment record to outseg */ if( !error ) { outseg->size = inseg->size; outseg->info = inseg->info; outseg->min = inseg->min; outseg->address = out_offset >> new_shift_count; }