diff options
Diffstat (limited to 'generic/tclIOUtil.c')
-rw-r--r-- | generic/tclIOUtil.c | 16 |
1 files changed, 12 insertions, 4 deletions
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) { |