Exemplo n.º 1
0
Arquivo: libio.c Projeto: JWasm/JWlink
void LibWrite( libfile lio, void *buff, file_offset len )
{
    file_offset num;

    if( len > WRITE_FILE_BUFFER_SIZE ) {
        LibFlush( lio );
        if( write( lio->io, buff, len ) != len ) {
            LibWriteError( lio );
        }
        return;
    }
    num = min( WRITE_FILE_BUFFER_SIZE - lio->buf_size, len );
    memcpy( lio->buffer + lio->buf_size, buff, num );
    len -= num;
    lio->buf_size += num;
    if( len ) {
        LibFlush( lio );
        memcpy( lio->buffer, (char *)buff + num, len );
        lio->buf_size = len;
    }
}
Exemplo n.º 2
0
Arquivo: libio.c Projeto: JWasm/JWlink
void LibClose( libfile lio )
{
    if( lio->access & O_WRONLY ) {
        LibFlush( lio );
    }
    if( close( lio->io ) != 0 ) {
        LibWriteError( lio );
    }
    if( fileList == lio ) {
        fileList = fileList->next;
    }
    if( lio->next ) {
        lio->next->prev = lio->prev;
    }
    if( lio->prev ) {
        lio->prev->next = lio->next;
    }
    MemFreeGlobal( lio->name );
    MemFreeGlobal( lio );
}
Exemplo n.º 3
0
Arquivo: libio.c Projeto: JWasm/JWlink
void LibSeek( libfile lio, long where, int whence )
{
    if( lio->access & O_WRONLY ) {
        LibFlush( lio );
    } else {
        if( whence == SEEK_END ) {
            where += filelength( lio->io ) - LibTell( lio );
            whence = SEEK_CUR;
        } else if( whence == SEEK_SET ) {
            where -= LibTell( lio );
            whence = SEEK_CUR;
        }
        if( ( lio->buf_pos >= -where ) && ( lio->buf_pos + where < lio->buf_size ) ) {
            lio->buf_pos += where;
            return;
        }
        where -= lio->buf_size - lio->buf_pos;
    }
    lseek( lio->io, where, whence );
    lio->buf_size = 0;
    lio->buf_pos = 0;
}
Exemplo n.º 4
0
void LibSeek( libfile lio, long where, int whence )
{
    if( lio->write_to ) {
        LibFlush( lio );
    } else {
        if( whence == SEEK_END ) {
            where += lio->endpos - LibTell( lio );
            whence = SEEK_CUR;
        } else if( whence == SEEK_SET ) {
            where -= LibTell( lio );
            whence = SEEK_CUR;
        }
        if( ( lio->buf_pos >= -where ) && ( lio->buf_pos + where < lio->buf_size ) ) {
            lio->buf_pos += where;
            return;
        }
        where -= lio->buf_size - lio->buf_pos;
    }
    fseek( lio->io, where, whence );
    lio->buf_size = 0;
    lio->buf_pos = 0;
}