diff -Naur patch-2.7.1/src/inp.c patch-2.7.1-p/src/inp.c --- patch-2.7.1/src/inp.c 2012-09-19 05:07:31 +0400 +++ patch-2.7.1-p/src/inp.c 2013-02-24 13:50:56 +0400 @@ -231,7 +231,11 @@ { if (S_ISREG (instat.st_mode)) { +#ifdef __CYGWIN__ + int ifd = safe_open (filename, O_RDONLY | (binary_transput ?: O_TEXT), 0); +#else int ifd = safe_open (filename, O_RDONLY|binary_transput, 0); +#endif size_t buffered = 0, n; if (ifd < 0) pfatal ("can't open file %s", quotearg (filename)); diff -Naur patch-2.7.1/src/patch.c patch-2.7.1-p/src/patch.c --- patch-2.7.1/src/patch.c 2012-09-28 14:43:12 +0400 +++ patch-2.7.1-p/src/patch.c 2013-02-24 13:51:50 +0400 @@ -798,7 +798,11 @@ "", " -d DIR --directory=DIR Change the working directory to DIR first.", " --reject-format=FORMAT Create 'context' or 'unified' rejects.", +#ifdef __CYGWIN__ +" --binary Read data in binary mode. Writing data is always binary.", +#else " --binary Read and write data in binary mode.", +#endif " --read-only=BEHAVIOR How to handle read-only input files: 'ignore' that they", " are read-only, 'warn' (default), or 'fail'.", "", @@ -1526,9 +1530,15 @@ static FILE * create_output_file (char const *name, int open_flags) { +#ifdef __CYGWIN__ + int fd = create_file (name, O_WRONLY | O_BINARY | open_flags, + instat.st_mode, true); + FILE *f = fdopen (fd, "wb"); +#else int fd = create_file (name, O_WRONLY | binary_transput | open_flags, instat.st_mode, true); FILE *f = fdopen (fd, binary_transput ? "wb" : "w"); +#endif if (! f) pfatal ("Can't create file %s", quotearg (name)); return f; diff -Naur patch-2.7.1/src/pch.c patch-2.7.1-p/src/pch.c --- patch-2.7.1/src/pch.c 2012-09-22 21:44:33 +0400 +++ patch-2.7.1-p/src/pch.c 2013-02-24 13:54:00 +0400 @@ -124,8 +124,10 @@ #if HAVE_SETMODE_DOS if (binary_transput) { +#ifndef __CYGWIN__ if (isatty (fileno (pfp))) fatal ("cannot read binary data from tty on this platform"); +#endif setmode (fileno (pfp), O_BINARY); } #endif @@ -2393,7 +2395,11 @@ verbosity == VERBOSE ? "" : "- ", outname); fflush (stdout); +#ifdef __CYGWIN__ + pipefp = popen(buf, "wb"); +#else pipefp = popen(buf, binary_transput ? "wb" : "w"); +#endif if (!pipefp) pfatal ("Can't open pipe to %s", quotearg (buf)); }