コード例 #1
0
ファイル: semraw.c プロジェクト: MikeyG/open-watcom-v2
RcStatus SemCopyDataUntilEOF( WResFileOffset offset, WResFileID handle,
                         void *buff, int buffsize, int *err_code )
/****************************************************************/
{
    bool            error;
    WResFileSSize   numread;

    if( RCSEEK( handle, offset, SEEK_SET ) == -1 ) {
        *err_code = errno;
        return( RS_READ_ERROR );
    }

    numread = RCREAD( handle, buff, buffsize );
    while( numread != 0 ) {
        if( RCIOERR( handle, numread ) ) {
            *err_code = errno;
            return( RS_READ_ERROR );
        }
        error = ResWrite( buff, numread, CurrResFile.handle );
        if( error ) {
            *err_code = LastWresErr();
            return( RS_WRITE_ERROR );
        }
        numread = RCREAD( handle, buff, buffsize );
    }

    return( RS_OK );
}
コード例 #2
0
ファイル: dbtable.c プロジェクト: ABratovic/open-watcom-v2
static RcStatus readDBRanges( WResFileID handle )
{
    WResFileSSize       numread;

    numread = RCREAD( handle, &charInfo.begchars, 256 );
    if( numread != 256 ) {
        return( RCIOERR( handle, numread ) ? RS_READ_ERROR : RS_READ_INCMPLT );
    }
    return( RS_OK );
}
コード例 #3
0
ファイル: semsnglw.c プロジェクト: MikeyG/open-watcom-v2
/*
 * ReadBitmapInfoHeader-
 * NB when an error occurs this func must return without altering errno
 */
static RcStatus ReadBitmapInfoHeader( BitmapInfoHeader * head, WResFileID handle )
/********************************************************************************/
{
    WResFileSSize   numread;

    numread = RCREAD( handle, head, sizeof(BitmapInfoHeader) );
    if( numread == sizeof( BitmapInfoHeader ) )
        return( RS_OK );
    return( RCIOERR( handle, numread ) ? RS_READ_ERROR : RS_READ_INCMPLT );
}
コード例 #4
0
ファイル: semsngl2.c プロジェクト: ABratovic/open-watcom-v2
static RcStatus readFontInfo( WResFileID handle, FontInfo *info, int *err_code )
/******************************************************************************/
{
    WResFileSSize   numread;

    numread = RCREAD( handle, info, sizeof( FontInfo ) );
    if( numread != sizeof( FontInfo ) ) {
        *err_code = errno;
        return( RCIOERR( handle, numread ) ? RS_READ_ERROR : RS_READ_INCMPLT );
    }
    return( RS_OK );
}
コード例 #5
0
ファイル: semutil.c プロジェクト: ABratovic/open-watcom-v2
/*
 * CopyData -
 */
RcStatus CopyData( uint_32 offset, uint_32 length, WResFileID handle,
                void *buff, int buffsize, int *err_code )
/***************************************************************************/
{
    bool            error;
    WResFileSSize   numread;

    if( RCSEEK( handle, offset, SEEK_SET ) == -1 ) {
        *err_code = errno;
        return( RS_READ_ERROR );
    }

    while( length > buffsize ) {
        numread = RCREAD( handle, buff, buffsize );
        if( numread != buffsize ) {
            *err_code = errno;
            return( RCIOERR( handle, numread ) ? RS_READ_ERROR : RS_READ_INCMPLT );
        }
        length -= buffsize;
        error = ResWrite( buff, buffsize, CurrResFile.handle );
        if( error ) {
            *err_code = LastWresErr();
            return( RS_WRITE_ERROR );
        }
    }

    numread = RCREAD( handle, buff, length );
    if( numread != length ) {
        *err_code = errno;
        return( RCIOERR( handle, numread ) ? RS_READ_ERROR : RS_READ_INCMPLT );
    }
    error = ResWrite( buff, length, CurrResFile.handle );
    if( error ) {
        *err_code = errno;
        return( RS_WRITE_ERROR );
    }

    return( RS_OK );
} /* CopyData */
コード例 #6
0
ファイル: dbtable.c プロジェクト: ABratovic/open-watcom-v2
static RcStatus readDBTable( WResFileID handle )
{
    WResFileSSize       numread;
    int                 size;

    size = charInfo.header.num_entries * sizeof( uint_16 );
    charInfo.entries = RCALLOC( size );
    numread = RCREAD( handle, charInfo.entries, size );
    if( numread != size ) {
        return( RCIOERR( handle, numread ) ? RS_READ_ERROR : RS_READ_INCMPLT );
    }
    return( RS_OK );
}
コード例 #7
0
ファイル: dbtable.c プロジェクト: ABratovic/open-watcom-v2
static RcStatus readDBIndex( WResFileID handle )
{
    WResFileSSize       numread;
    int                 size;

    size = charInfo.header.num_indices * sizeof( DBIndexEntry );
    charInfo.index = RCALLOC( size );
    numread = RCREAD( handle, charInfo.index, size );
    if( numread != size ) {
        return( RCIOERR( handle, numread ) ? RS_READ_ERROR : RS_READ_INCMPLT );
    }
    return( RS_OK );
}
コード例 #8
0
ファイル: semsnglw.c プロジェクト: MikeyG/open-watcom-v2
static RcStatus readBitmapFileHeader( WResFileID handle, BitmapFileHeader *head,
                                        int *err_code )
/******************************************************************************/
{
    WResFileSSize   numread;

    numread = RCREAD( handle, head, sizeof(BitmapFileHeader) );
    if( numread != sizeof( BitmapFileHeader ) ) {
        *err_code = errno;
        return( RCIOERR( handle, numread ) ? RS_READ_ERROR : RS_READ_INCMPLT );
    }
    return( RS_OK );
}
コード例 #9
0
ファイル: semsnglw.c プロジェクト: MikeyG/open-watcom-v2
static RcStatus readCurFileDirEntry( CurFileDirEntry * entry, WResFileID handle,
                                        int *err_code )
/******************************************************************************/
{
    WResFileSSize   numread;

    numread = RCREAD( handle, entry, sizeof(CurFileDirEntry) );
    if( numread != sizeof(CurFileDirEntry ) ) {
        *err_code = errno;
        return( RCIOERR( handle, numread ) ? RS_READ_ERROR : RS_READ_INCMPLT );
    }
    return( RS_OK );
} /* readCurFileDirEntry */
コード例 #10
0
ファイル: semsnglw.c プロジェクト: MikeyG/open-watcom-v2
static RcStatus readIcoCurFileDirHeader( IconCurDirHeader * head,
                                    WResFileID handle, int *err_code )
/********************************************************************/
{
    WResFileSSize   numread;

    numread = RCREAD( handle, head, sizeof(IconCurDirHeader) );
    if( numread != sizeof( IconCurDirHeader ) ) {
        *err_code = errno;
        return( RCIOERR( handle, numread ) ? RS_READ_ERROR : RS_READ_INCMPLT );
    }
    return( RS_OK );
} /* readIcoCurFileDirHeader */
コード例 #11
0
ファイル: exeseg.c プロジェクト: ABratovic/open-watcom-v2
/*
 * readSegTable
 * NB when an error occurs this function must return without altering errno
 */
static RcStatus readSegTable( WResFileID handle, uint_32 offset, SegTable * seg )
{
    int             tablesize;
    WResFileSSize   numread;

    tablesize = seg->NumSegs * sizeof(segment_record);

    if( RCSEEK( handle, offset, SEEK_SET ) == -1 )
        return( RS_READ_ERROR );
    numread = RCREAD( handle, seg->Segments, tablesize );
    if( numread != tablesize ) {
        return( RCIOERR( handle, numread ) ? RS_READ_ERROR : RS_READ_INCMPLT );
    }
    return( RS_OK );

} /* readSegTable */
コード例 #12
0
ファイル: dbtable.c プロジェクト: ABratovic/open-watcom-v2
static RcStatus readDBHeader( WResFileID handle )
{
    WResFileSSize       numread;

    numread = RCREAD( handle, &charInfo.header, sizeof( DBTableHeader ) );
    if( numread != sizeof( DBTableHeader ) ) {
        return( RCIOERR( handle, numread  ) ? RS_READ_ERROR : RS_READ_INCMPLT );
    }
    if( charInfo.header.sig[0] != DB_TABLE_SIG_1 ||
        charInfo.header.sig[1] != DB_TABLE_SIG_2 ) {
        return( RS_BAD_FILE_FMT );
    }
    if( charInfo.header.ver != DB_TABLE_VER ) {
        return( RS_WRONG_VER );
    }
    return( RS_OK );
}
コード例 #13
0
ファイル: exeseg.c プロジェクト: ABratovic/open-watcom-v2
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;
    }