cygwin fflush stopgap

Eric Blake ebb9@byu.net
Sat Jun 23 02:22:00 GMT 2007


This is a stopgap patch that will restore proper fflush operation on cygwin: 
since cygwin no longer supports 32-bit access, _seek64 is valid if _seek is.  
However, it is incomplete - a full implementation needs to take into account 
reentrancy issues (platforms that use _stdout_r will work incorrectly if we 
don't implement _fflush_r), and must be ready to deal with the case where _seek 
is valid but _seek64 is NULL (such as when using open instead of open64) to 
correctly fail with EFBIG when trying to flush beyond 32-bit offsets.  
Therefore, I'm not providing a changelog or checking this in.  It is only 
informational for those working on cygwin, while I finish off work on the 
correct and complete patch.


Index: libc/stdio/fflush.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdio/fflush.c,v
retrieving revision 1.10
diff -u -p -r1.10 fflush.c
--- libc/stdio/fflush.c	4 Jun 2007 18:10:17 -0000	1.10
+++ libc/stdio/fflush.c	22 Jun 2007 20:36:40 -0000
@@ -90,7 +90,13 @@ _DEFUN(fflush, (fp),
   t = fp->_flags;
   if ((t & __SWR) == 0)
     {
-      _fpos_t _EXFUN((*seekfn), (struct _reent *, _PTR, _fpos_t, int));
+#ifdef __LARGE64_FILES
+      _fpos64_t _EXFUN((*seekfn), (struct _reent *, _PTR, _fpos64_t, int))
+         = fp->_seek64;
+#else
+      _fpos_t _EXFUN((*seekfn), (struct _reent *, _PTR, _fpos_t, int))
+         = fp->_seek;
+#endif
 
       /* For a read stream, an fflush causes the next seek to be
          unoptimized (i.e. forces a system-level seek).  This conforms
@@ -104,9 +110,13 @@ _DEFUN(fflush, (fp),
          this seek to be deferred until necessary, but we choose to do it here
          to make the change simpler, more contained, and less likely
          to miss a code scenario.  */
-      if ((fp->_r > 0 || fp->_ur > 0) && (seekfn = fp->_seek) != NULL)
+      if ((fp->_r > 0 || fp->_ur > 0) && seekfn != NULL)
         {
+#ifdef __LARGE64_FILES
+          _fpos64_t curoff;
+#else
           _fpos_t curoff;
+#endif
 
           /* Get the physical position we are at in the file.  */
           if (fp->_flags & __SOFF)
@@ -114,7 +124,7 @@ _DEFUN(fflush, (fp),
           else
             {
               /* We don't know current physical offset, so ask for it.  */
-              curoff = seekfn (_REENT, fp->_cookie, (_fpos_t) 0, SEEK_CUR);
+              curoff = seekfn (_REENT, fp->_cookie, 0, SEEK_CUR);
               if (curoff == -1L)
                 {
                   _funlockfile (fp);




More information about the Newlib mailing list