Fossil SCM
Update the blob_write_to_file() routine so that it correctly handles binary files being send to standard output.
Commit
83a574b019b02b2f25b5007f4f7e56c534b481fa
Parent
4d408219bdd62db…
1 file changed
+14
-2
+14
-2
| --- src/blob.c | ||
| +++ src/blob.c | ||
| @@ -766,12 +766,24 @@ | ||
| 766 | 766 | int blob_write_to_file(Blob *pBlob, const char *zFilename){ |
| 767 | 767 | FILE *out; |
| 768 | 768 | int wrote; |
| 769 | 769 | |
| 770 | 770 | if( zFilename[0]==0 || (zFilename[0]=='-' && zFilename[1]==0) ){ |
| 771 | - fossil_puts(blob_str(pBlob), 0); | |
| 772 | - return blob_size(pBlob); | |
| 771 | + int n; | |
| 772 | +#if defined(_WIN32) | |
| 773 | + if( _isatty(fileno(stdout)) ){ | |
| 774 | + char *z; | |
| 775 | + z = fossil_utf8_to_console(blob_str(pBlob)); | |
| 776 | + n = strlen(z); | |
| 777 | + fwrite(z, 1, n, stdout); | |
| 778 | + free(z); | |
| 779 | + return n; | |
| 780 | + } | |
| 781 | +#endif | |
| 782 | + n = blob_size(pBlob); | |
| 783 | + fwrite(blob_buffer(pBlob), 1, n, stdout); | |
| 784 | + return n; | |
| 773 | 785 | }else{ |
| 774 | 786 | int i, nName; |
| 775 | 787 | char *zName, zBuf[1000]; |
| 776 | 788 | |
| 777 | 789 | nName = strlen(zFilename); |
| 778 | 790 |
| --- src/blob.c | |
| +++ src/blob.c | |
| @@ -766,12 +766,24 @@ | |
| 766 | int blob_write_to_file(Blob *pBlob, const char *zFilename){ |
| 767 | FILE *out; |
| 768 | int wrote; |
| 769 | |
| 770 | if( zFilename[0]==0 || (zFilename[0]=='-' && zFilename[1]==0) ){ |
| 771 | fossil_puts(blob_str(pBlob), 0); |
| 772 | return blob_size(pBlob); |
| 773 | }else{ |
| 774 | int i, nName; |
| 775 | char *zName, zBuf[1000]; |
| 776 | |
| 777 | nName = strlen(zFilename); |
| 778 |
| --- src/blob.c | |
| +++ src/blob.c | |
| @@ -766,12 +766,24 @@ | |
| 766 | int blob_write_to_file(Blob *pBlob, const char *zFilename){ |
| 767 | FILE *out; |
| 768 | int wrote; |
| 769 | |
| 770 | if( zFilename[0]==0 || (zFilename[0]=='-' && zFilename[1]==0) ){ |
| 771 | int n; |
| 772 | #if defined(_WIN32) |
| 773 | if( _isatty(fileno(stdout)) ){ |
| 774 | char *z; |
| 775 | z = fossil_utf8_to_console(blob_str(pBlob)); |
| 776 | n = strlen(z); |
| 777 | fwrite(z, 1, n, stdout); |
| 778 | free(z); |
| 779 | return n; |
| 780 | } |
| 781 | #endif |
| 782 | n = blob_size(pBlob); |
| 783 | fwrite(blob_buffer(pBlob), 1, n, stdout); |
| 784 | return n; |
| 785 | }else{ |
| 786 | int i, nName; |
| 787 | char *zName, zBuf[1000]; |
| 788 | |
| 789 | nName = strlen(zFilename); |
| 790 |