Fossil SCM

Update the blob_write_to_file() routine so that it correctly handles binary files being send to standard output.

drh 2011-11-02 15:23 trunk
Commit 83a574b019b02b2f25b5007f4f7e56c534b481fa
1 file changed +14 -2
+14 -2
--- src/blob.c
+++ src/blob.c
@@ -766,12 +766,24 @@
766766
int blob_write_to_file(Blob *pBlob, const char *zFilename){
767767
FILE *out;
768768
int wrote;
769769
770770
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;
773785
}else{
774786
int i, nName;
775787
char *zName, zBuf[1000];
776788
777789
nName = strlen(zFilename);
778790
--- 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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button