This is the mail archive of the
ecos-discuss@sources.redhat.com
mailing list for the eCos project.
Re: [eCos] a question about ROMFS
jjtsai wrote:
> > I'll see if I can work on a better patch.
> That would be great!
Can you try the attached patch for me please? I haven't even tried
compiling it yet nevermind testing it, but I was hoping you could do that
instead :-). Let me know how it goes. Then I'll check it in.
Jifl
--
Red Hat, Rustat House, Clifton Road, Cambridge, UK. Tel: +44 (1223) 271062
Maybe this world is another planet's Hell -Aldous Huxley || Opinions==mine
Come to the Red Hat TechWorld open source conference in Brussels!
Keynotes, techie talks and exhibitions http://www.redhat-techworld.com/
Index: include/stream.inl
===================================================================
RCS file: /home/cvs/ecc/ecc/language/c/libc/stdio/current/include/stream.inl,v
retrieving revision 1.3
diff -u -5 -p -r1.3 stream.inl
--- include/stream.inl 2001/03/15 20:30:22 1.3
+++ include/stream.inl 2001/07/17 20:05:43
@@ -361,19 +361,19 @@ Cyg_StdioStream::get_position( fpos_t *p
// set absolute position
inline Cyg_ErrNo
Cyg_StdioStream::set_position( fpos_t pos, int whence )
{
+ CYG_ASSERTCLASS( this, "Stream object is not a valid stream!" );
+
#ifndef CYGPKG_LIBC_STDIO_FILEIO
// this is currently a workaround until we have real files
// this will be corrected when we decide the true filesystem interface
Cyg_ErrNo err;
cyg_uint8 c;
- CYG_ASSERTCLASS( this, "Stream object is not a valid stream!" );
-
if ((whence != SEEK_CUR) || pos < 0)
return ENOSYS;
if (!lock_me())
return EBADF; // assume file is now invalid
@@ -396,18 +396,46 @@ Cyg_StdioStream::set_position( fpos_t po
return ENOERR;
#else
- Cyg_ErrNo err;
- off_t newpos = pos;
-
- CYG_ASSERTCLASS( this, "Stream object is not a valid stream!" );
-
if (!lock_me())
return EBADF; // assume file is now invalid
+ if ( whence != SEEK_END ) {
+ cyg_ucount32 bytesavail = bytes_available_to_read();
+ off_t abspos = (whence == SEEK_CUR) ? position + pos : pos;
+ off_t posdiff = abspos - position;
+
+ if ( bytesavail > posdiff ) {
+ // can just "seek" within the existing buffer
+#ifdef CYGFUN_LIBC_STDIO_ungetc
+ if (flags.unread_char_buf_in_use) {
+ flags.unread_char_buf_in_use = false;
+ posdiff--;
+ }
+#endif
+#ifdef CYGSEM_LIBC_STDIO_WANT_BUFFERED_IO
+ if (posdiff>0 && flags.buffering) {
+ io_buf.set_bytes_read(posdiff);
+ posdiff=0;
+ } else
+#endif
+ if (posdiff>0 && flags.readbuf_char_in_use) {
+ flags.readbuf_char_in_use = false;
+ posdiff--;
+ }
+ CYG_ASSERT(posdiff==0, "Failed to seek within buffer correctly");
+
+ position = abspos;
+ unlock_me();
+ return ENOERR;
+ }
+ }
+
+ Cyg_ErrNo err;
+ off_t newpos = pos;
err = cyg_stdio_lseek( my_device, &newpos, whence );
if( err == ENOERR )
{
// Clean out the buffer. Flush output if any present,
@@ -420,14 +448,14 @@ Cyg_StdioStream::set_position( fpos_t po
flags.unread_char_buf_in_use = false;
#endif
// Clear EOF indicator.
flags.at_eof = false;
- }
-
- if( err == ENOERR )
+
+ // update stream pos
position = newpos;
+ }
unlock_me();
return err;
#endif