[ECOS] fseek +ramfs +SEEK_CUR problems

senthil kumar t senthilnow@rediffmail.com
Thu Aug 29 06:55:00 GMT 2002


hi,
 with reference to the thread "a question about romfs" dated 16 
jul 2001 from jjtsai i am writing this mail, i saw the following 
lines in one of the mails in that thread

" A fseek(,,SEEK_CUR) after fread() will cause inconsistency 
between
 (CYG_StdioStream) real_stream.position
 and "fp->f_offset". See also stream.inl and rom_fs.c"

 i also observed similar condition in the case of ramfs also when 
a file is opened is r+ mode and when fseek is done with SEEK_CUR 
flag the fp->f_offset doesn't exactly reflect the right offset, so 
i have made some change in the fseek.cxx which fixes this problem, 
basically i am doing a real_stream->get_position and initialising 
the offset correctly.

i have modified the fseek function as such.

externC int
fseek( FILE * stream , long int offset , int whence  )
{
    Cyg_StdioStream *real_stream = (Cyg_StdioStream *)stream;
    Cyg_ErrNo err;
    int ret = 0;
    fpos_t seekcur_pos;// ADDED FOR FIX

    CYG_REPORT_FUNCNAME( "fgetpos" );

//START_FIX
    if (whence==SEEK_CUR)
   {
    err= real_stream->get_position(&seekcur_pos);
    offset+=seekcur_pos;
    whence=SEEK_SET;
   }
//END_FIX

    err = real_stream->set_position( (fpos_t)offset, whence );

    if( err != ENOERR )
    {
        errno = err;
        ret = -1;
    }

    CYG_REPORT_RETVAL( ret );
    return ret;
}

i have 2 questions

1) is this the right place for the fix?
2) what is the better way of resolving that inconsistency?

thankx in advance
senthil kumar




--
Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss




More information about the Ecos-discuss mailing list