m4-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Changes to m4/src/Attic/debug.c,v [branch-1_4]


From: Eric Blake
Subject: Changes to m4/src/Attic/debug.c,v [branch-1_4]
Date: Mon, 11 Sep 2006 13:17:22 +0000

CVSROOT:        /sources/m4
Module name:    m4
Branch:         branch-1_4
Changes by:     Eric Blake <ericb>      06/09/11 13:17:21

Index: src/debug.c
===================================================================
RCS file: /sources/m4/m4/src/Attic/debug.c,v
retrieving revision 1.1.1.1.2.9
retrieving revision 1.1.1.1.2.10
diff -u -b -r1.1.1.1.2.9 -r1.1.1.1.2.10
--- src/debug.c 23 Aug 2006 11:30:11 -0000      1.1.1.1.2.9
+++ src/debug.c 11 Sep 2006 13:17:21 -0000      1.1.1.1.2.10
@@ -142,7 +142,7 @@
 
   if (debug != NULL && debug != stdout)
     {
-      if (fstat (fileno (stdout), &stdout_stat) < 0)
+      if (fstat (STDOUT_FILENO, &stdout_stat) < 0)
        return;
       if (fstat (fileno (debug), &debug_stat) < 0)
        return;
@@ -175,6 +175,27 @@
   fflush (stderr);
   if (debug != NULL && debug != stdout && debug != stderr)
     fflush (debug);
+  /* POSIX requires that if m4 doesn't consume all input, but stdin is
+     opened on a seekable file, that the file pointer be left at the
+     next character on exit (but places no restrictions on the file
+     pointer location on a non-seekable file).  It also requires that
+     fflush() followed by fseek() on an input file set the underlying
+     file pointer.  However, fflush() on a non-seekable file can lose
+     buffered data, which we might otherwise want to process after
+     syscmd.  Hence, we must check whether stdin is seekable.  We must
+     also be tolerant of operating with stdin closed, so we don't
+     report any failures in this attempt.  The stdio-safer module and
+     friends are essential, so that if stdin was closed, this lseek is
+     not on some other file that we have since opened.  Mingw has bugs
+     when using fseek on text files, so we only strive for POSIX
+     behavior when we detect a UNIX environment.  */
+#if UNIX
+  if (lseek (STDIN_FILENO, 0, SEEK_CUR) >= 0
+      && fflush (stdin) == 0)
+    {
+      fseek (stdin, 0, SEEK_CUR);
+    }
+#endif /* UNIX */
 }
 
 /*-------------------------------------------------------------------------.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]