diff options
author | Zack Weinberg <zack@gcc.gnu.org> | 1999-02-09 13:48:34 +0000 |
---|---|---|
committer | Zack Weinberg <zack@gcc.gnu.org> | 1999-02-09 13:48:34 +0000 |
commit | 6458033dde6a2db8e5dd2a140805b58a3ed3747f (patch) | |
tree | 15001c4ddc6e98d67f3c219961f582253c3b7649 /gcc | |
parent | 8ec65f13b03f68893379947b8611a280cabe5b74 (diff) | |
download | gcc-6458033dde6a2db8e5dd2a140805b58a3ed3747f.zip gcc-6458033dde6a2db8e5dd2a140805b58a3ed3747f.tar.gz gcc-6458033dde6a2db8e5dd2a140805b58a3ed3747f.tar.bz2 |
[multiple changes]
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
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog | 10 | ||||
-rw-r--r-- | gcc/cppfiles.c | 29 | ||||
-rw-r--r-- | gcc/system.h | 33 |
3 files changed, 70 insertions, 2 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 60d81ad..c375916 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -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. diff --git a/gcc/cppfiles.c b/gcc/cppfiles.c index 5092b91..b43d280 100644 --- a/gcc/cppfiles.c +++ b/gcc/cppfiles.c @@ -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; diff --git a/gcc/system.h b/gcc/system.h index 40efc9a..f0c4208 100644 --- a/gcc/system.h +++ b/gcc/system.h @@ -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" |