+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.
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)
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. */
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;
#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"