- Cygwin sftp/sftp-server binary mode patch from Corinna Vinschen
   <vinschen@redhat.com>
diff --git a/ChangeLog b/ChangeLog
index b612b02..918c843 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,7 @@
 20010414
  - Sync with OpenBSD glob.c, strlcat.c and vis.c changes
+ - Cygwin sftp/sftp-server binary mode patch from Corinna Vinschen 
+   <vinschen@redhat.com>
 
 20010413
  - OpenBSD CVS Sync                                                           
@@ -5052,4 +5054,4 @@
  - Wrote replacements for strlcpy and mkdtemp
  - Released 1.0pre1
 
-$Id: ChangeLog,v 1.1108 2001/04/13 14:22:33 djm Exp $
+$Id: ChangeLog,v 1.1109 2001/04/13 14:28:42 djm Exp $
diff --git a/openbsd-compat/bsd-cygwin_util.c b/openbsd-compat/bsd-cygwin_util.c
index ea981be..36f13e3 100644
--- a/openbsd-compat/bsd-cygwin_util.c
+++ b/openbsd-compat/bsd-cygwin_util.c
@@ -15,12 +15,11 @@
 
 #include "includes.h"
 
-RCSID("$Id: bsd-cygwin_util.c,v 1.3 2001/02/18 01:30:56 djm Exp $");
+RCSID("$Id: bsd-cygwin_util.c,v 1.4 2001/04/13 14:28:42 djm Exp $");
 
 #ifdef HAVE_CYGWIN
 
 #include <fcntl.h>
-#include <io.h>
 #include <stdlib.h>
 #include <sys/vfs.h>
 #include <windows.h>
diff --git a/openbsd-compat/bsd-cygwin_util.h b/openbsd-compat/bsd-cygwin_util.h
index e2d4b4d..7879501 100644
--- a/openbsd-compat/bsd-cygwin_util.h
+++ b/openbsd-compat/bsd-cygwin_util.h
@@ -13,13 +13,15 @@
  * binary mode on Windows systems.
  */
 
-/* $Id: bsd-cygwin_util.h,v 1.3 2001/02/18 01:30:56 djm Exp $ */
+/* $Id: bsd-cygwin_util.h,v 1.4 2001/04/13 14:28:43 djm Exp $ */
 
 #ifndef _BSD_CYGWIN_UTIL_H
 #define _BSD_CYGWIN_UTIL_H
 
 #ifdef HAVE_CYGWIN
 
+#include <io.h>
+
 int binary_open(const char *filename, int flags, ...);
 int binary_pipe(int fd[2]);
 int check_nt_auth(int pwd_authenticated, uid_t uid);
diff --git a/scp.c b/scp.c
index d317a71..c654cb6 100644
--- a/scp.c
+++ b/scp.c
@@ -291,6 +291,9 @@
 		case 't':	/* "to" */
 			iamremote = 1;
 			tflag = 1;
+#ifdef HAVE_CYGWIN
+			setmode(0, O_BINARY);
+#endif
 			break;
 		default:
 			usage();
diff --git a/sftp-server.c b/sftp-server.c
index 0695a98..75c19c8 100644
--- a/sftp-server.c
+++ b/sftp-server.c
@@ -1043,6 +1043,11 @@
 	in = dup(STDIN_FILENO);
 	out = dup(STDOUT_FILENO);
 
+#ifdef HAVE_CYGWIN
+	setmode(in, O_BINARY);
+	setmode(out, O_BINARY);
+#endif
+
 	max = 0;
 	if (in > max)
 		max = in;