Index: src/dd.c
===================================================================
RCS file: /cvsroot/coreutils/coreutils/src/dd.c,v
retrieving revision 1.180
diff -u -r1.180 dd.c
--- src/dd.c	12 May 2005 07:54:10 -0000	1.180
+++ src/dd.c	13 May 2005 16:25:31 -0000
@@ -1324,6 +1324,13 @@
 static void
 set_fd_flags (int fd, int add_flags, char const *name)
 {
+  /* Cygwin cannot set binary vs. text with fcntl.  */
+  if (add_flags & (O_BINARY | O_TEXT))
+    {
+      if (SET_MODE (fd, add_flags & (O_BINARY | O_TEXT)) < 0)
+	error (EXIT_FAILURE, errno, _("setting flags for %s"), quote (name));
+      add_flags &= ~(O_BINARY | O_TEXT);
+    }
   if (add_flags)
     {
       int old_flags = fcntl (fd, F_GETFL);
@@ -1599,10 +1606,13 @@
   if (input_file == NULL)
     {
       input_file = _("standard input");
+      SET_BINARY (STDIN_FILENO);
       set_fd_flags (STDIN_FILENO, input_flags, input_file);
     }
   else
     {
+      if ((input_flags & (O_BINARY | O_TEXT)) == 0)
+	input_flags |= O_BINARY;
       if (open_fd (STDIN_FILENO, input_file, O_RDONLY | input_flags, 0) < 0)
 	error (EXIT_FAILURE, errno, _("opening %s"), quote (input_file));
     }
@@ -1615,6 +1625,7 @@
   if (output_file == NULL)
     {
       output_file = _("standard output");
+      SET_BINARY (STDOUT_FILENO);
       set_fd_flags (STDOUT_FILENO, output_flags, output_file);
     }
   else
@@ -1622,6 +1633,7 @@
       mode_t perms = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
       int opts
 	= (output_flags
+	   | (output_flags & (O_BINARY | O_TEXT) ? 0 : O_BINARY)
 	   | (conversions_mask & C_NOCREAT ? 0 : O_CREAT)
 	   | (conversions_mask & C_EXCL ? O_EXCL : 0)
 	   | (seek_records || (conversions_mask & C_NOTRUNC) ? 0 : O_TRUNC));
