This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: new module 'freadseek'


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

According to Eric Blake on 3/1/2008 10:44 AM:
|
| Somehow, the tweaks you did to the raw _fp to account for the 1-byte
| readahead buffer from the arbitrary ungetc trip up the subsequent fseek.
| I'm in the process of compiling a debug version of cygwin to try to find
| out more details why cygwin's fseek failed, but it may take a while.

On further investigation, I think this is a true bug in newlib's stdio,
and not in your code.  This simpler program fails some of the time, but
not if there was a previous ftell:

$ cat foo.c
#include <stdio.h>
#include <stdlib.h>

int
main (int argc, char* argv[])
{
~  int i1, i2;
~  if (argc > 1)
~    {
~      i2 = ftell (stdin);
~      printf ("i2=%d\n", i2);
~    }
~  /* Test behaviour after arbitrary ungetc.  */
~  fgetc (stdin);
~  if (argc > 1)
~    {
~      i2 = ftell (stdin);
~      printf ("i2=%d\n", i2);
~    }
~  ungetc ('@', stdin);
~  if (argc > 1)
~    {
~      i2 = ftell (stdin);
~      printf ("i2=%d\n", i2);
~    }
~  i1 = fseek (stdin, 2, SEEK_CUR);
~  i2 = ftell (stdin);
~  printf ("i1=%d i2=%d\n", i1, i2);
~  return 0;
}
$ ./foo < foo.c
i1=-1 i2=-536
$ ./foo a < foo.c
i2=0
i2=1
i2=0
i1=0 i2=2

- --
Don't work too hard, make some time for fun as well!

Eric Blake             ebb9@byu.net
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFHyb4684KuGfSFAYARAgoEAJ4j2E2sDIPckneFx7fN71gY9DxqbQCeMLoH
GIvjgX1hpmjqnhjZF9fErJA=
=pyQX
-----END PGP SIGNATURE-----


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]