Fossil SCM
Fix "Corrupt line endings in cat/finfo on Windows with CR+LF files", reported on ML.
Commit
f2fc37c063af9fae4fac87d754ba7448ddc7ef8c
Parent
fd1a2921995a38e…
1 file changed
+10
+10
| --- src/blob.c | ||
| +++ src/blob.c | ||
| @@ -24,10 +24,14 @@ | ||
| 24 | 24 | # include "miniz.c" |
| 25 | 25 | #else |
| 26 | 26 | # include <zlib.h> |
| 27 | 27 | #endif |
| 28 | 28 | #include "blob.h" |
| 29 | +#if defined(_WIN32) | |
| 30 | +#include <fcntl.h> | |
| 31 | +#include <io.h> | |
| 32 | +#endif | |
| 29 | 33 | |
| 30 | 34 | #if INTERFACE |
| 31 | 35 | /* |
| 32 | 36 | ** A Blob can hold a string or a binary object of arbitrary size. The |
| 33 | 37 | ** size changes as necessary. |
| @@ -823,12 +827,18 @@ | ||
| 823 | 827 | nWrote = blob_size(pBlob); |
| 824 | 828 | #if defined(_WIN32) |
| 825 | 829 | if( fossil_utf8_to_console(blob_buffer(pBlob), nWrote, 0) >= 0 ){ |
| 826 | 830 | return nWrote; |
| 827 | 831 | } |
| 832 | + fflush(stdout); | |
| 833 | + _setmode(_fileno(stdout), _O_BINARY); | |
| 828 | 834 | #endif |
| 829 | 835 | fwrite(blob_buffer(pBlob), 1, nWrote, stdout); |
| 836 | +#if defined(_WIN32) | |
| 837 | + fflush(stdout); | |
| 838 | + _setmode(_fileno(stdout), _O_TEXT); | |
| 839 | +#endif | |
| 830 | 840 | }else{ |
| 831 | 841 | file_mkfolder(zFilename, 1); |
| 832 | 842 | out = fossil_fopen(zFilename, "wb"); |
| 833 | 843 | if( out==0 ){ |
| 834 | 844 | fossil_fatal_recursive("unable to open file \"%s\" for writing", |
| 835 | 845 |
| --- src/blob.c | |
| +++ src/blob.c | |
| @@ -24,10 +24,14 @@ | |
| 24 | # include "miniz.c" |
| 25 | #else |
| 26 | # include <zlib.h> |
| 27 | #endif |
| 28 | #include "blob.h" |
| 29 | |
| 30 | #if INTERFACE |
| 31 | /* |
| 32 | ** A Blob can hold a string or a binary object of arbitrary size. The |
| 33 | ** size changes as necessary. |
| @@ -823,12 +827,18 @@ | |
| 823 | nWrote = blob_size(pBlob); |
| 824 | #if defined(_WIN32) |
| 825 | if( fossil_utf8_to_console(blob_buffer(pBlob), nWrote, 0) >= 0 ){ |
| 826 | return nWrote; |
| 827 | } |
| 828 | #endif |
| 829 | fwrite(blob_buffer(pBlob), 1, nWrote, stdout); |
| 830 | }else{ |
| 831 | file_mkfolder(zFilename, 1); |
| 832 | out = fossil_fopen(zFilename, "wb"); |
| 833 | if( out==0 ){ |
| 834 | fossil_fatal_recursive("unable to open file \"%s\" for writing", |
| 835 |
| --- src/blob.c | |
| +++ src/blob.c | |
| @@ -24,10 +24,14 @@ | |
| 24 | # include "miniz.c" |
| 25 | #else |
| 26 | # include <zlib.h> |
| 27 | #endif |
| 28 | #include "blob.h" |
| 29 | #if defined(_WIN32) |
| 30 | #include <fcntl.h> |
| 31 | #include <io.h> |
| 32 | #endif |
| 33 | |
| 34 | #if INTERFACE |
| 35 | /* |
| 36 | ** A Blob can hold a string or a binary object of arbitrary size. The |
| 37 | ** size changes as necessary. |
| @@ -823,12 +827,18 @@ | |
| 827 | nWrote = blob_size(pBlob); |
| 828 | #if defined(_WIN32) |
| 829 | if( fossil_utf8_to_console(blob_buffer(pBlob), nWrote, 0) >= 0 ){ |
| 830 | return nWrote; |
| 831 | } |
| 832 | fflush(stdout); |
| 833 | _setmode(_fileno(stdout), _O_BINARY); |
| 834 | #endif |
| 835 | fwrite(blob_buffer(pBlob), 1, nWrote, stdout); |
| 836 | #if defined(_WIN32) |
| 837 | fflush(stdout); |
| 838 | _setmode(_fileno(stdout), _O_TEXT); |
| 839 | #endif |
| 840 | }else{ |
| 841 | file_mkfolder(zFilename, 1); |
| 842 | out = fossil_fopen(zFilename, "wb"); |
| 843 | if( out==0 ){ |
| 844 | fossil_fatal_recursive("unable to open file \"%s\" for writing", |
| 845 |