summaryrefslogtreecommitdiffstats
path: root/generic/tclEncoding.c
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2014-11-15 21:08:57 (GMT)
committerdgp <dgp@users.sourceforge.net>2014-11-15 21:08:57 (GMT)
commit55688af5e97888536930067e5e23a686661a0b1c (patch)
tree7dfba7ed7d0c7b5acced0020322271a79aa378d2 /generic/tclEncoding.c
parentc3c06423586daccaeba84d4aacf23f375121434c (diff)
downloadtcl-55688af5e97888536930067e5e23a686661a0b1c.zip
tcl-55688af5e97888536930067e5e23a686661a0b1c.tar.gz
tcl-55688af5e97888536930067e5e23a686661a0b1c.tar.bz2
Tcl_ExternalToUtf appends a terminating NUL to its encoded results.
Perhaps this is a welcome convenience for some callers, but not for Tcl's I/O system, which has no need for that. Added a new flag value TCL_ENCODING_NO_TERMINATE that callers can use to suppress this behavior. This means buffers don't require so much padding, and a tiny bit of processing is saved. Update I/O callers to use the feature.
Diffstat (limited to 'generic/tclEncoding.c')
-rw-r--r--generic/tclEncoding.c22
1 files changed, 15 insertions, 7 deletions
diff --git a/generic/tclEncoding.c b/generic/tclEncoding.c
index d246cb2..0446816 100644
--- a/generic/tclEncoding.c
+++ b/generic/tclEncoding.c
@@ -1204,6 +1204,7 @@ Tcl_ExternalToUtf(
{
const Encoding *encodingPtr;
int result, srcRead, dstWrote, dstChars;
+ int noTerminate = flags & TCL_ENCODING_NO_TERMINATE;
Tcl_EncodingState state;
if (encoding == NULL) {
@@ -1230,17 +1231,24 @@ Tcl_ExternalToUtf(
dstCharsPtr = &dstChars;
}
- /*
- * If there are any null characters in the middle of the buffer, they will
- * converted to the UTF-8 null character (\xC080). To get the actual \0 at
- * the end of the destination buffer, we need to append it manually.
- */
+ if (!noTerminate) {
+ /*
+ * If there are any null characters in the middle of the buffer,
+ * they will converted to the UTF-8 null character (\xC080). To get
+ * the actual \0 at the end of the destination buffer, we need to
+ * append it manually. First make room for it...
+ */
- dstLen--;
+ dstLen--;
+ }
result = encodingPtr->toUtfProc(encodingPtr->clientData, src, srcLen,
flags, statePtr, dst, dstLen, srcReadPtr, dstWrotePtr,
dstCharsPtr);
- dst[*dstWrotePtr] = '\0';
+ if (!noTerminate) {
+ /* ...and then append it */
+
+ dst[*dstWrotePtr] = '\0';
+ }
return result;
}