summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--generic/tclIO.c7
-rw-r--r--generic/tclIO.h2
-rw-r--r--tests/io.test21
3 files changed, 29 insertions, 1 deletions
diff --git a/generic/tclIO.c b/generic/tclIO.c
index 8a7cb2b..ff74a99 100644
--- a/generic/tclIO.c
+++ b/generic/tclIO.c
@@ -7552,7 +7552,7 @@ Tcl_Eof(
ChannelState *statePtr = ((Channel *) chan)->state;
/* State of real channel structure. */
- if (GotFlag(statePtr, CHANNEL_NONBLOCKING)
+ if (GotFlag(statePtr, CHANNEL_NONBLOCKING|CHANNEL_FCOPY)
&& GotFlag(statePtr, CHANNEL_ENCODING_ERROR)) {
return 0;
}
@@ -9694,6 +9694,7 @@ CopyData(
* the bottom of the stack.
*/
+ SetFlag(inStatePtr, CHANNEL_FCOPY);
inBinary = (inStatePtr->encoding == NULL);
outBinary = (outStatePtr->encoding == NULL);
sameEncoding = inStatePtr->encoding == outStatePtr->encoding
@@ -9809,6 +9810,7 @@ CopyData(
TclDecrRefCount(bufObj);
bufObj = NULL;
}
+ ResetFlag(inStatePtr, CHANNEL_FCOPY);
return TCL_OK;
}
}
@@ -9900,6 +9902,7 @@ CopyData(
TclDecrRefCount(bufObj);
bufObj = NULL;
}
+ ResetFlag(inStatePtr, CHANNEL_FCOPY);
return TCL_OK;
}
@@ -9922,6 +9925,7 @@ CopyData(
TclDecrRefCount(bufObj);
bufObj = NULL;
}
+ ResetFlag(inStatePtr, CHANNEL_FCOPY);
return TCL_OK;
}
} /* while */
@@ -9974,6 +9978,7 @@ CopyData(
}
}
}
+ ResetFlag(inStatePtr, CHANNEL_FCOPY);
return result;
}
diff --git a/generic/tclIO.h b/generic/tclIO.h
index 62cf6e8..588c7d4 100644
--- a/generic/tclIO.h
+++ b/generic/tclIO.h
@@ -235,6 +235,8 @@ typedef struct ChannelState {
* flushed after every newline. */
#define CHANNEL_UNBUFFERED (1<<5) /* Output to the channel must always
* be flushed immediately. */
+#define CHANNEL_FCOPY (1<<6) /* Channel is currently doing an fcopy
+ * mode. */
#define BG_FLUSH_SCHEDULED (1<<7) /* A background flush of the queued
* output buffers has been
* scheduled. */
diff --git a/tests/io.test b/tests/io.test
index 59b6c66..065eb4c 100644
--- a/tests/io.test
+++ b/tests/io.test
@@ -7692,6 +7692,27 @@ test io-52.19 {coverage of eofChar handling} {
close $out
file size $path(test2)
} 8
+test io-52.20 {TclCopyChannel & encodings} -setup {
+ set out [open $path(utf8-fcopy.txt) w]
+ fconfigure $out -encoding utf-8 -translation lf
+ puts $out "Á"
+ close $out
+} -constraints {fcopy} -body {
+ # binary to encoding => the input has to be
+ # in utf-8 to make sense to the encoder
+
+ set in [open $path(utf8-fcopy.txt) r]
+ set out [open $path(kyrillic.txt) w]
+
+ # Using "-encoding ascii" means reading the "Á" gives an error
+ fconfigure $in -encoding ascii -strictencoding 1
+ fconfigure $out -encoding koi8-r -translation lf
+
+ fcopy $in $out
+} -cleanup {
+ close $in
+ close $out
+} -returnCodes 1 -match glob -result {error reading "file*": illegal byte sequence}
test io-52.21 {TclCopyChannel & encodings} -setup {
set out [open $path(utf8-fcopy.txt) w]
fconfigure $out -encoding utf-8 -translation lf