freading has an undefined value after repositioning a read-write stream.
authorBruno Haible <bruno@clisp.org>
Sun, 29 Apr 2007 08:38:22 +0000 (08:38 +0000)
committerBruno Haible <bruno@clisp.org>
Sun, 29 Apr 2007 08:38:22 +0000 (08:38 +0000)
ChangeLog
lib/freading.h
lib/fwriting.h
tests/test-freading.c
tests/test-fwriting.c

index e538c9c8b9774b61a20ca953891dcab47748b664..f819138fd5ea13c1289a60aaf0eefa23085f27a1 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2007-04-29  Bruno Haible  <bruno@clisp.org>
+
+       * lib/freading.h: Improve comments.
+       * lib/fwriting.h: Likewise.
+       * tests/test-freading.c (main): Don't check freading immediately after
+       repositioning. Needed for glibc.
+
 2007-04-29  Bruno Haible  <bruno@clisp.org>
 
        * lib/freading.c (freading): Trivial simplification.
 2007-04-29  Bruno Haible  <bruno@clisp.org>
 
        * lib/freading.c (freading): Trivial simplification.
index 1845de1a85572497f319480e66bad92abaa60d10..9bd2eaf3abd47213a3163d5e684bfca787dea415 100644 (file)
    writing and there is no current read operation (such as fputc).
 
    freading and fwriting will never both be true.  If STREAM supports
    writing and there is no current read operation (such as fputc).
 
    freading and fwriting will never both be true.  If STREAM supports
-   both reads and writes, then both freading and fwriting might be
-   false when the stream is first opened, after repositioning (such as
-   fseek, fsetpos, or rewind), after read encounters EOF, or after
-   fflush, depending on the underlying implementation.
+   both reads and writes, then:
+     - both freading and fwriting might be false when the stream is first
+       opened, after read encounters EOF, or after fflush,
+     - freading might be false or true and fwriting might be false
+       after repositioning (such as fseek, fsetpos, or rewind),
+   depending on the underlying implementation.
 
    STREAM must not be wide-character oriented.  */
 
 
    STREAM must not be wide-character oriented.  */
 
index b354186c85877d1a1a801e34214af80253a4dc0c..cba2b132b433cf287bd362bb28fcf30099a985eb 100644 (file)
    as fputc).
 
    freading and fwriting will never both be true.  If STREAM supports
    as fputc).
 
    freading and fwriting will never both be true.  If STREAM supports
-   both reads and writes, then both freading and fwriting might be
-   false when the stream is first opened, after repositioning (such as
-   fseek, fsetpos, or rewind), after read encounters EOF, or after
-   fflush, depending on the underlying implementation.
+   both reads and writes, then:
+     - both freading and fwriting might be false when the stream is first
+       opened, after read encounters EOF, or after fflush,
+     - freading might be false or true and fwriting might be false
+       after repositioning (such as fseek, fsetpos, or rewind),
+   depending on the underlying implementation.
 
    STREAM must not be wide-character oriented.  */
 
 
    STREAM must not be wide-character oriented.  */
 
index 3d69c404eaad456dee448348b344dc31e5691425..b2f6fc7b07c4be60510430efe8cd97fab10ef8c8 100644 (file)
@@ -97,7 +97,9 @@ main ()
   ASSERT (!freading (fp));
   if (fseek (fp, 0, SEEK_END))
     goto skip;
   ASSERT (!freading (fp));
   if (fseek (fp, 0, SEEK_END))
     goto skip;
-  ASSERT (!freading (fp));
+  /* freading (fp) is undefined here, because on some implementations (e.g.
+     glibc) fseek causes a buffer to be read.
+     fwriting (fp) is undefined as well.  */
   if (fclose (fp))
     goto skip;
 
   if (fclose (fp))
     goto skip;
 
@@ -135,7 +137,9 @@ main ()
   ASSERT (!freading (fp));
   if (fseek (fp, 0, SEEK_END))
     goto skip;
   ASSERT (!freading (fp));
   if (fseek (fp, 0, SEEK_END))
     goto skip;
-  ASSERT (!freading (fp));
+  /* freading (fp) is undefined here, because on some implementations (e.g.
+     glibc) fseek causes a buffer to be read.
+     fwriting (fp) is undefined as well.  */
   if (fclose (fp))
     goto skip;
 
   if (fclose (fp))
     goto skip;
 
index 690a35f3060d6b08ee6d32d01e67185b80879d5e..0f97df5ccf59616ce2d8aff0fc0e0191f1bf2532 100644 (file)
@@ -97,7 +97,9 @@ main ()
   ASSERT (fwriting (fp));
   if (fseek (fp, 0, SEEK_END))
     goto skip;
   ASSERT (fwriting (fp));
   if (fseek (fp, 0, SEEK_END))
     goto skip;
-  /* fwriting (fp) is undefined here, but freading (fp) is false.  */
+  /* freading (fp) is undefined here, because on some implementations (e.g.
+     glibc) fseek causes a buffer to be read.
+     fwriting (fp) is undefined as well.  */
   if (fclose (fp))
     goto skip;
 
   if (fclose (fp))
     goto skip;
 
@@ -135,7 +137,9 @@ main ()
   ASSERT (fwriting (fp));
   if (fseek (fp, 0, SEEK_END))
     goto skip;
   ASSERT (fwriting (fp));
   if (fseek (fp, 0, SEEK_END))
     goto skip;
-  /* fwriting (fp) is undefined here, but freading (fp) is false.  */
+  /* freading (fp) is undefined here, because on some implementations (e.g.
+     glibc) fseek causes a buffer to be read.
+     fwriting (fp) is undefined as well.  */
   if (fclose (fp))
     goto skip;
 
   if (fclose (fp))
     goto skip;