]> gcc.gnu.org Git - gcc.git/commitdiff
[multiple changes]
authorZack Weinberg <zack@gcc.gnu.org>
Tue, 9 Feb 1999 13:48:34 +0000 (13:48 +0000)
committerZack Weinberg <zack@gcc.gnu.org>
Tue, 9 Feb 1999 13:48:34 +0000 (13:48 +0000)
1999-02-09 16:42 -0500  Zack Weinberg  <zack@rabi.columbia.edu>
* cppfiles.c (finclude):  Handle pipes properly under old BSD
          derivatives.
1999-02-09 16:42 -0500  Melissa O'Neill <oneill@cs.sfu.ca>
* system.h: Provide fallback definitions for S_ISCHR,
          S_ISSOCK, S_ISFIFO, O_NONBLOCK, and O_NOCTTY.

From-SVN: r25111

gcc/ChangeLog
gcc/cppfiles.c
gcc/system.h

index 60d81ad71ff915df85e258c5d7ac6748eef12870..c3759169a52ca732795db2b3d712c3ce462012d5 100644 (file)
@@ -1,3 +1,13 @@
+1999-02-09 16:42 -0500  Zack Weinberg  <zack@rabi.columbia.edu>
+
+       * cppfiles.c (finclude):  Handle pipes properly under old BSD
+          derivatives.
+
+1999-02-09 16:42 -0500  Melissa O'Neill <oneill@cs.sfu.ca>
+
+       * system.h: Provide fallback definitions for S_ISCHR,
+          S_ISSOCK, S_ISFIFO, O_NONBLOCK, and O_NOCTTY.
+
 1999-02-09 10:30 -0500  Zack Weinberg  <zack@rabi.columbia.edu>
 
        * cpplib.c (do_define): Allow redefining __STDC__ with -D.
index 5092b916718c7063bfe50597b2f708fcd070f3ed..b43d280abd4bdbdb3fece4d6def070944b2cc506 100644 (file)
@@ -683,11 +683,27 @@ finclude (pfile, fd, ihash)
 
   fp = CPP_BUFFER (pfile);
 
+  /* 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.
+
+     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.
+
+     In all cases, read_and_prescan will resize the buffer if it
+     turns out there's more data than we thought.  */
+
   if (S_ISREG (st.st_mode))
     {
       /* off_t might have a wider range than size_t - in other words,
         the max size of a file might be bigger than the address
-        space, and we need to detect that now. */
+        space.  We can't handle a file that large.  (Anyone with
+         a single source file bigger than 4GB needs to rethink
+        their coding style.)  */
       st_size = (size_t) st.st_size;
       if ((unsigned HOST_WIDE_INT) st_size
          != (unsigned HOST_WIDE_INT) st.st_size)
@@ -696,7 +712,11 @@ finclude (pfile, fd, ihash)
          goto fail;
        }
     }
-  else if (S_ISFIFO (st.st_mode) || (S_ISCHR (st.st_mode) && isatty (fd)))
+  else if (S_ISFIFO (st.st_mode) || S_ISSOCK (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)
+          || (S_ISCHR (st.st_mode) && isatty (fd)))
     {
       /* Cannot get its file size before reading.  4k is a decent
          first guess. */
@@ -743,6 +763,11 @@ finclude (pfile, fd, ihash)
   return 0;
 }
 
+/* Given a path FNAME, extract the directory component and place it
+   onto the actual_dirs list.  Return a pointer to the allocated
+   file_name_list structure.  These structures are used to implement
+   current-directory "" include searching. */
+
 static struct file_name_list *
 actual_directory (pfile, fname)
      cpp_reader *pfile;
index 40efc9ac63b9a07cb5a1eeaa2deb103b2d8b68e8..f0c4208b2e8388a210e09c969959c9a642b6166c 100644 (file)
@@ -422,6 +422,39 @@ extern void abort ();
 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
 #endif
 
+/* Test if something is a character special file.  */
+#ifndef S_ISCHR
+#define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
+#endif
+
+/* Test if something is a socket.  */
+#ifndef S_ISSOCK
+# ifdef S_IFSOCK
+#   define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
+# else
+#   define S_ISSOCK(m) 0
+# endif
+#endif
+
+/* Test if something is a FIFO.  */
+#ifndef S_ISFIFO
+# ifdef S_IFIFO
+#  define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
+# else
+#  define S_ISFIFO(m) 0
+# endif
+#endif
+
+/* Approximate O_NONBLOCK.  */
+#ifndef O_NONBLOCK
+#define O_NONBLOCK O_NDELAY
+#endif
+
+/* Approximate O_NOCTTY.  */
+#ifndef O_NOCTTY
+#define O_NOCTTY 0
+#endif
+
 /* Get libiberty declarations. */
 #include "libiberty.h"
 
This page took 0.080186 seconds and 5 git commands to generate.