diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index bf1fd086f1066c32993423c0c041f25890c39c72..17494dcf9b37392fbce00c5dbca70d225a94f8c4 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,8 @@
+2002-05-13  Andris Pavenis  <pavenis@lanet.lv>
+
+	* cppfiles.c (open_file): Change mode (DJGPP only) of redirected
+	input to O_BINARY.
+
 2002-05-13  Jeffrey A Law  (law@redhat.com)
 
 	* i386.c (ia32_multipass_dfa_lookahead): Prototype.
diff --git a/gcc/cppfiles.c b/gcc/cppfiles.c
index 70ac9782f4de287834ae1f5255abc236c0d977d1..49c740dea4a2350f3cc9d554b4f0c6b64d7b268d 100644
--- a/gcc/cppfiles.c
+++ b/gcc/cppfiles.c
@@ -270,7 +270,15 @@ open_file (pfile, filename)
      Special case: the empty string is translated to stdin.  */
 
   if (filename[0] == '\0')
-    file->fd = 0;
+    {
+      file->fd = 0;
+#ifdef __DJGPP__
+      /* For DJGPP redirected input is opened in text mode. Change it
+         to binary mode.  */
+      if (! isatty (file->fd))
+        setmode (file->fd, O_BINARY);
+#endif
+    }
   else
     file->fd = open (file->name, O_RDONLY | O_NOCTTY | O_BINARY, 0666);