summaryrefslogtreecommitdiffstats
path: root/generic
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2012-02-19 15:21:27 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2012-02-19 15:21:27 (GMT)
commita09069115b1c5707f85d873526d0d7c9b2ace1fb (patch)
treec5b8bd708483807b0fd532e8596ef564c10fc5fe /generic
parent7695d3270788d56c1ba433909285dcab42414edb (diff)
downloadtcl-a09069115b1c5707f85d873526d0d7c9b2ace1fb.zip
tcl-a09069115b1c5707f85d873526d0d7c9b2ace1fb.tar.gz
tcl-a09069115b1c5707f85d873526d0d7c9b2ace1fb.tar.bz2
[Bug 3466099] BOM in Unicode
Diffstat (limited to 'generic')
-rw-r--r--generic/tclEncoding.c4
-rw-r--r--generic/tclIOUtil.c16
2 files changed, 14 insertions, 6 deletions
diff --git a/generic/tclEncoding.c b/generic/tclEncoding.c
index 9432c05..a4a7027 100644
--- a/generic/tclEncoding.c
+++ b/generic/tclEncoding.c
@@ -764,13 +764,13 @@ Tcl_GetEncodingNames(interp)
int
Tcl_SetSystemEncoding(interp, name)
Tcl_Interp *interp; /* Interp for error reporting, if not NULL. */
- CONST char *name; /* The name of the desired encoding, or NULL
+ CONST char *name; /* The name of the desired encoding, or NULL/""
* to reset to default encoding. */
{
Tcl_Encoding encoding;
Encoding *encodingPtr;
- if (name == NULL) {
+ if (!name || !*name) {
Tcl_MutexLock(&encodingMutex);
encoding = defaultEncoding;
encodingPtr = (Encoding *) encoding;
diff --git a/generic/tclIOUtil.c b/generic/tclIOUtil.c
index b54b76b..d5bb102 100644
--- a/generic/tclIOUtil.c
+++ b/generic/tclIOUtil.c
@@ -1755,11 +1755,19 @@ Tcl_FSEvalFile(interp, pathPtr)
* [Bug: 2040]
*/
Tcl_SetChannelOption(interp, chan, "-eofchar", "\32");
- if (Tcl_ReadChars(chan, objPtr, -1, 0) < 0) {
- Tcl_Close(interp, chan);
+ /* Try to read utf-8 BOM, if available */
+ if (Tcl_ReadChars(chan, objPtr, 1, 0) < 0) {
+ Tcl_Close(interp, chan);
Tcl_AppendResult(interp, "couldn't read file \"",
- Tcl_GetString(pathPtr),
- "\": ", Tcl_PosixError(interp), (char *) NULL);
+ Tcl_GetString(pathPtr), "\": ", Tcl_PosixError(interp), NULL);
+ goto end;
+ }
+ string = Tcl_GetString(objPtr);
+ if (Tcl_ReadChars(chan, objPtr, -1,
+ memcmp(string, "\xef\xbf\xbe", 3)) < 0) {
+ Tcl_Close(interp, chan);
+ Tcl_AppendResult(interp, "couldn't read file \"",
+ Tcl_GetString(pathPtr), "\": ", Tcl_PosixError(interp), NULL);
goto end;
}
if (Tcl_Close(interp, chan) != TCL_OK) {