delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2000/05/01/15:16:11

Date: Mon, 1 May 2000 13:04:46 -0700
From: Zack Weinberg <zack AT wolery DOT cumb DOT org>
To: Laurynas Biveinis <lauras AT softhome DOT net>
Cc: gcc-patches AT gcc DOT gnu DOT org, DJGPP Workers <djgpp-workers AT delorie DOT com>
Subject: Re: Minor DJGPP fixes
Message-ID: <20000501130446.D714@wolery.cumb.org>
References: <390C769C DOT 812EAB7D AT softhome DOT net> <20000501000928 DOT J11780 AT wolery DOT cumb DOT org> <390D7FF5 DOT 3042DEE AT softhome DOT net>
Mime-Version: 1.0
User-Agent: Mutt/1.1.12i
In-Reply-To: <390D7FF5.3042DEE@softhome.net>; from lauras@softhome.net on Mon, May 01, 2000 at 04:00:37PM +0300
Reply-To: djgpp-workers AT delorie DOT com
Errors-To: nobody AT delorie DOT com
X-Mailing-List: djgpp-workers AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

On Mon, May 01, 2000 at 04:00:37PM +0300, Laurynas Biveinis wrote:
> 
> Thanks for your feedback, Zack.
> 
> Zack Weinberg wrote:
> > Therefore, I'd be willing to dump the fcntl() call entirely and open
> > the file in blocking mode on all hosts.  Does anyone else have an
> > opinion?
> 
> OK, I'll delay fcntl() part of patch until I see your solution.

I'm now convinced that nonblocking open is more trouble than it's
worth.  I've committed the following patch:

	* cppfiles.c (open_include_file): Open file in blocking mode.
	(read_include_file): Don't fcntl(fd, F_SETFL, 0) anymore.
	Only exclude block devices and directories.

Please let me know if it doesn't fix your problem.

zw

===================================================================
Index: cppfiles.c
--- cppfiles.c	2000/04/30 17:11:25	1.58
+++ cppfiles.c	2000/05/01 19:59:51
@@ -218,11 +218,10 @@ file_cleanup (pbuf, pfile)
    with calling open is in one place, and if we ever need more, it'll
    be in one place too.
 
-   Open files in nonblocking mode, so we don't get stuck if someone
-   clever has asked cpp to process /dev/rmt0.  read_include_file
-   will check that we have a real file to work with.  Also take care
-   not to acquire a controlling terminal by mistake (this can't happen
-   on sane systems, but paranoia is a virtue).
+   We used to open files in nonblocking mode, but that caused more
+   problems than it solved.  Do take care not to acquire a controlling
+   terminal by mistake (this can't happen on sane systems, but
+   paranoia is a virtue).
 
    Use the three-argument form of open even though we aren't
    specifying O_CREAT, to defend against broken system headers.  */
@@ -232,7 +231,7 @@ open_include_file (pfile, filename)
      cpp_reader *pfile ATTRIBUTE_UNUSED;
      const char *filename;
 {
-  return open (filename, O_RDONLY|O_NONBLOCK|O_NOCTTY, 0666);
+  return open (filename, O_RDONLY|O_NOCTTY, 0666);
 }
 
 /* Search for include file FNAME in the include chain starting at
@@ -708,19 +707,18 @@ read_include_file (pfile, fd, ihash)
 
   if (fstat (fd, &st) < 0)
     goto perror_fail;
-  if (fcntl (fd, F_SETFL, 0) == -1)  /* turn off nonblocking mode */
-    goto perror_fail;
 
   /* If fd points to a plain file, we know how big it is, so we can
      allocate the buffer all at once.  If fd is a pipe or terminal, we
      can't.  Most C source files are 4k or less, so we guess that.  If
-     fd is something weird, like a block device or a directory, we
-     don't want to read it at all.
+     fd is something weird, like a directory, we don't want to read it
+     at all.
 
      Unfortunately, different systems use different st.st_mode values
      for pipes: some have S_ISFIFO, some S_ISSOCK, some are buggy and
-     zero the entire struct stat except a couple fields.  Hence the
-     mess below.
+     zero the entire struct stat except a couple fields.  Hence we don't
+     even try to figure out what something is, except for plain files,
+     directories, and block devices.
 
      In all cases, read_and_prescan will resize the buffer if it
      turns out there's more data than we thought.  */
@@ -740,22 +738,20 @@ read_include_file (pfile, fd, ihash)
 	  goto fail;
 	}
     }
-  else if (S_ISFIFO (st.st_mode) || S_ISSOCK (st.st_mode)
-	   /* Permit any kind of character device: the sensible ones are
-	      ttys and /dev/null, but weeding out the others is too hard.  */
-	   || S_ISCHR (st.st_mode)
-	   /* Some 4.x (x<4) derivatives have a bug that makes fstat() of a
-	      socket or pipe return a stat struct with most fields zeroed.  */
-	   || (st.st_mode == 0 && st.st_nlink == 0 && st.st_size == 0))
+  else if (S_ISBLK (st.st_mode))
     {
-      /* Cannot get its file size before reading.  4k is a decent
-         first guess. */
-      st_size = 4096;
+      cpp_error (pfile, "%s is a block device", ihash->name);
+      goto fail;
     }
-  else
+  else if (S_ISDIR (st.st_mode))
     {
-      cpp_error (pfile, "`%s' is not a file, pipe, or tty", ihash->name);
+      cpp_error (pfile, "%s is a directory", ihash->name);
       goto fail;
+    }
+  else
+    {
+      /* We don't know how big this is.  4k is a decent first guess.  */
+      st_size = 4096;
     }
 
   /* Read the file, converting end-of-line characters and trigraphs

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019