This is the mail archive of the
ecos-discuss@sources.redhat.com
mailing list for the eCos project.
Re: bug in fseek
- From: Andrew Lunn <andrew dot lunn at ascom dot ch>
- To: senthil kumar t <senthilnow at rediffmail dot com>
- Cc: ecos-discuss at sources dot redhat dot com, Jonathan Larmour <jifl at jifvik dot org>
- Date: Sun, 1 Sep 2002 18:00:06 +0200
- Subject: Re: [ECOS] bug in fseek
- References: <20020901153004.10558.qmail@webmail6.rediffmail.com>
Hi
so sore this post the last time you posted it. This is not my area of
knowledge so i left it to others. Since no one replied i took a closer
look this time.
I don't think your solution is the correct one. Since whence is passed
to set_position it should do the arithmetic. Doing it here there is a
danger the addition is done twice.
Looking further, i could only find one implementation of set_position.
packages/language/c/libc/stdio/current/include/stream.inl
There is two code paths depend if you have CYGPKG_LIBC_STDIO_FILEIO or
not. Do you have this enabled?
At first glance there seems to be something funny when its not
enabled:
// Drain read buffer
for ( ; whence > 0 ; whence-- ) {
err = read_byte( &c );
if (err == EAGAIN)
err=refill_read_buffer();
// if read_byte retured error, or refill_read_buffer returned error
if (err) {
unlock_me();
return err;
} // if
} // for
Looping on whence seems very strange to me. I would expect it to loop
on pos. Jifl, is this a typo?
Since you mention ramfs, i assume you have CYGPKG_LIBC_STDIO_FILEIO
enabled. In that case it does not used this code path so this will not
be affecting you.
Are you seeking backwards or forwards? If you are seeking backwards
more than 1 you need to have CYGSEM_LIBC_STDIO_WANT_BUFFERED_IO
enabled. Do you have assets enable? If so you should of got an assert
in this case.
I don't claim to fully understand this code, but it looks OK to
me. Could you produce a test case?
Andrew
On Sun, Sep 01, 2002 at 03:30:04PM -0000, senthil kumar t wrote:
> hi,
> There is an inconsistency between
> (CYG_StdioStream) real_stream.position
> and "fp->f_offset" in the ramfs operation of fseek when the
> whence flag is set to SEEK_CUR, so the right position of the
> offset from the opened file is not obtained so some fix should be
> made to make the inconsitency vanish,
> i have comeup with some solution which will circumvent this
> problem.
> The fseek function has been moddified as such in fseek.cxx
>
> 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;
> }
>
> real_stream->get_position should be done to find out the current
> position bcos fp->f_offset could be different if opened in r+
> mode, this bug is still there in the latest ecos cvs i checked out
> before a week and my fix makes that work correctly as expected.
>
> with regards
> 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
>
--
Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss