bug-texinfo
[Top][All Lists]
Advanced

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

Re: texinfo-5.9.90 pretest available


From: Ken Brown
Subject: Re: texinfo-5.9.90 pretest available
Date: Fri, 27 Feb 2015 11:02:00 -0500
User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0

On 2/27/2015 9:39 AM, Eli Zaretskii wrote:
Date: Fri, 27 Feb 2015 13:43:48 +0000
From: Gavin Smith <address@hidden>
Cc: Eli Zaretskii <address@hidden>, Karl Berry <address@hidden>, Texinfo 
<address@hidden>

On 27 February 2015 at 13:13, Ken Brown <address@hidden> wrote:
No, it turns out that it has to do with buffered I/O.  See the thread
starting here:

   https://cygwin.com/ml/cygwin/2015-02/msg00887.html

Replacing the fseek in line 841 by another call to freopen fixes the
problem.  I don't know if that's the best solution.


The setvbuf solution might work - I'm not sure if the buffering
property of the FILE stream will be inherited by the subprocess, or
just the file descriptor (i.e. what "open" would return instead of
what "fopen" would return).

Isn't FILE buffering implemented in libc, i.e. in user-space private
to the application?  If it is, then the buffer is not inherited.

The buffering that the Cygwin maintainer alluded to is the one below
stdio, in 'read' and its ilk.  That one emulates the OS buffering, and
is indeed inherited together with the file descriptor.

The main thing would be if we are reading from an uncompressed file
in install-info (the parent process) - buffering should be turned
back on in that case. Another solution would be to read the first
few bytes of the file using "open", "read" and "lseek", and make a
FILE stream afterwards from the file descriptor; this would avoid
any buffering done by the high-level FILE streams.

I'm actually asking myself why do we redirect stdin to the file before
reading it, instead of using 'fopen' to read the few first bytes, and
then, only if it is compressed, redirect stdin to it and call 'popen'.
Wouldn't that work around the problem?

Like this?

Index: install-info/install-info.c
===================================================================
--- install-info/install-info.c (revision 6157)
+++ install-info/install-info.c (working copy)
@@ -700,35 +700,35 @@
     opened_filename = &local_opened_filename;

   *opened_filename = filename;
-  f = freopen (*opened_filename, FOPEN_RBIN, stdin);
+  f = fopen (*opened_filename, FOPEN_RBIN);
   if (!f)
     {
       *opened_filename = concat (filename, ".gz", "");
-      f = freopen (*opened_filename, FOPEN_RBIN, stdin);
+      f = fopen (*opened_filename, FOPEN_RBIN);
     }
   if (!f)
     {
       free (*opened_filename);
       *opened_filename = concat (filename, ".xz", "");
-      f = freopen (*opened_filename, FOPEN_RBIN, stdin);
+      f = fopen (*opened_filename, FOPEN_RBIN);
     }
   if (!f)
     {
       free (*opened_filename);
       *opened_filename = concat (filename, ".bz2", "");
-      f = freopen (*opened_filename, FOPEN_RBIN, stdin);
+      f = fopen (*opened_filename, FOPEN_RBIN);
     }
   if (!f)
     {
       free (*opened_filename);
       *opened_filename = concat (filename, ".lz", "");
-      f = freopen (*opened_filename, FOPEN_RBIN, stdin);
+      f = fopen (*opened_filename, FOPEN_RBIN);
     }
   if (!f)
     {
      free (*opened_filename);
      *opened_filename = concat (filename, ".lzma", "");
-     f = freopen (*opened_filename, FOPEN_RBIN, stdin);
+     f = fopen (*opened_filename, FOPEN_RBIN);
     }
 #ifdef __MSDOS__
   if (!f)
@@ -735,13 +735,13 @@
     {
       free (*opened_filename);
       *opened_filename = concat (filename, ".igz", "");
-      f = freopen (*opened_filename, FOPEN_RBIN, stdin);
+      f = fopen (*opened_filename, FOPEN_RBIN);
     }
   if (!f)
     {
       free (*opened_filename);
       *opened_filename = concat (filename, ".inz", "");
-      f = freopen (*opened_filename, FOPEN_RBIN, stdin);
+      f = fopen (*opened_filename, FOPEN_RBIN);
     }
 #endif /* __MSDOS__ */
   if (!f)
@@ -757,7 +757,7 @@
           (*create_callback) (filename);

           /* And try opening it again.  */
-          f = freopen (*opened_filename, FOPEN_RBIN, stdin);
+          f = fopen (*opened_filename, FOPEN_RBIN);
           if (!f)
             return 0;
         }
@@ -843,6 +843,9 @@

   if (*compression_program)
     { /* It's compressed, so open a pipe.  */
+      f = freopen (*opened_filename, FOPEN_RBIN, stdin);
+      if (!f)
+       return 0;
       char *command = concat (*compression_program, " -d", "");
       f = popen (command, "r");
       if (! f)





reply via email to

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