[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: 'fflush' test failure on Cygwin
From: |
Bruno Haible |
Subject: |
Re: 'fflush' test failure on Cygwin |
Date: |
Thu, 26 Apr 2007 11:26:21 +0200 |
User-agent: |
KMail/1.5.4 |
Eric Blake wrote:
> Meanwhile, I'm checking in this.
>
> 2007-04-25 Eric Blake <address@hidden>
>
> * lib/fpurge.c (includes): Use stdlib.h for free.
> * tests/test-fflush.c (main): Also test fflush-fseeko.
Thanks. Addendum:
2007-04-26 Bruno Haible <address@hidden>
* modules/fflush-tests (Depends-on): Add fseeko.
*** modules/fflush-tests 17 Apr 2007 03:38:08 -0000 1.3
--- modules/fflush-tests 26 Apr 2007 08:17:48 -0000
***************
*** 2,7 ****
--- 2,8 ----
tests/test-fflush.c
Depends-on:
+ fseeko
configure.ac:
With your additions, the test now fails again on MacOS X. It is because
the stream caches the fd's position, hence the lseek() calls confuse
ftell(). This fixes it:
2007-04-26 Bruno Haible <address@hidden>
* tests/test-fflush.c (main): Also check the ftell result after
fflush and fseek/fseeko.
* lib/fflush.c (rpl_fflush): For BSD implementations, update the
file descriptor position cache in the stream.
* lib/fseeko.c (rpl_fseeko): Likewise.
*** tests/test-fflush.c 25 Apr 2007 13:22:15 -0000 1.2
--- tests/test-fflush.c 26 Apr 2007 09:19:52 -0000
***************
*** 74,79 ****
--- 74,86 ----
unlink ("test-fflush.txt");
return 1;
}
+ if (ftell (f) != 5)
+ {
+ fputs ("ftell result is wrong after fseek.\n", stderr);
+ fclose (f);
+ unlink ("test-fflush.txt");
+ return 1;
+ }
/* Check that file reading resumes at correct location. */
if (fgetc (f) != '6')
{
***************
*** 106,111 ****
--- 113,125 ----
unlink ("test-fflush.txt");
return 1;
}
+ if (ftell (f) != 6)
+ {
+ fputs ("ftell result is wrong after fseek.\n", stderr);
+ fclose (f);
+ unlink ("test-fflush.txt");
+ return 1;
+ }
/* Check that file reading resumes at correct location. */
if (fgetc (f) != '7')
{
*** lib/fflush.c 23 Apr 2007 12:49:50 -0000 1.4
--- lib/fflush.c 26 Apr 2007 09:19:52 -0000
***************
*** 58,64 ****
semantics of fpurge are now appropriate to clear the buffer. To
avoid losing data, the lseek is also necessary. */
result = fpurge (stream);
! if (result == 0 && lseek (fileno (stream), pos, SEEK_SET) == -1)
return EOF;
! return result;
}
--- 58,71 ----
semantics of fpurge are now appropriate to clear the buffer. To
avoid losing data, the lseek is also necessary. */
result = fpurge (stream);
! if (result != 0)
! return result;
! pos = lseek (fileno (stream), pos, SEEK_SET);
! if (pos == -1)
return EOF;
! #if defined __sferror /* FreeBSD, NetBSD, OpenBSD, MacOS X,
Cygwin */
! stream->_offset = pos;
! stream->_flags |= __SOFF;
! #endif
! return 0;
}
*** lib/fseeko.c 25 Apr 2007 09:14:49 -0000 1.1
--- lib/fseeko.c 26 Apr 2007 09:19:52 -0000
***************
*** 66,72 ****
#else
#error "Please port gnulib fseeko.c to your platform! Look at the code in
fpurge.c, then report this to bug-gnulib."
#endif
! return (lseek (fileno (fp), offset, whence) == (off_t)(-1) ? -1 : 0);
else
return fseeko (fp, offset, whence);
}
--- 66,89 ----
#else
#error "Please port gnulib fseeko.c to your platform! Look at the code in
fpurge.c, then report this to bug-gnulib."
#endif
! {
! off_t pos = lseek (fileno (fp), offset, whence);
! if (pos == -1)
! {
! #if defined __sferror /* FreeBSD, NetBSD, OpenBSD, MacOS X,
Cygwin */
! fp->_flags &= ~__SOFF;
! #endif
! return -1;
! }
! else
! {
! #if defined __sferror /* FreeBSD, NetBSD, OpenBSD, MacOS X,
Cygwin */
! fp->_offset = pos;
! fp->_flags |= __SOFF;
! #endif
! return 0;
! }
! }
else
return fseeko (fp, offset, whence);
}
Bruno
- Re: 'fflush' test failure on Cygwin, (continued)
- Re: 'fflush' test failure on Cygwin, Eric Blake, 2007/04/23
- new module 'fseeko', Bruno Haible, 2007/04/25
- Re: new module 'fseeko', Eric Blake, 2007/04/25
- Re: new module 'fseeko', Bruno Haible, 2007/04/26
- Re: new module 'fseeko', Bruno Haible, 2007/04/28
- Re: new module 'fseeko', Paul Eggert, 2007/04/25
- Re: new module 'fseeko', Bruno Haible, 2007/04/26
- new module 'ftello', Bruno Haible, 2007/04/25
- Re: 'fflush' test failure on Cygwin, Bruno Haible, 2007/04/25
- Re: 'fflush' test failure on Cygwin, Eric Blake, 2007/04/25
- Re: 'fflush' test failure on Cygwin,
Bruno Haible <=
- Re: 'fflush' test failure on Cygwin, Eric Blake, 2007/04/26
- Re: 'fflush' test failure on Cygwin, Bruno Haible, 2007/04/25