summaryrefslogtreecommitdiffstats
path: root/generic/tkOption.c
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2016-07-21 20:06:34 (GMT)
committerdgp <dgp@users.sourceforge.net>2016-07-21 20:06:34 (GMT)
commita80e603c517d2682ef25067ac6daf1d2692d5864 (patch)
treecd7aaee28e7876e8bfdd77e835c534b13cbe5f98 /generic/tkOption.c
parent682d30ed7f59d3c732d08cf6ccc715e738784453 (diff)
parent2aa945d6a8109c74d9ff3331fb99a093635e0cd7 (diff)
downloadtk-a80e603c517d2682ef25067ac6daf1d2692d5864.zip
tk-a80e603c517d2682ef25067ac6daf1d2692d5864.tar.gz
tk-a80e603c517d2682ef25067ac6daf1d2692d5864.tar.bz2
Diffstat (limited to 'generic/tkOption.c')
-rw-r--r--generic/tkOption.c42
1 files changed, 9 insertions, 33 deletions
diff --git a/generic/tkOption.c b/generic/tkOption.c
index d758b6f..24e7fb3 100644
--- a/generic/tkOption.c
+++ b/generic/tkOption.c
@@ -560,7 +560,7 @@ Tk_GetOption(
count -= levelPtr[-1].bases[currentStack];
}
- if (currentStack && CLASS) {
+ if (currentStack & CLASS) {
nodeId = winClassId;
} else {
nodeId = winNameId;
@@ -1080,10 +1080,10 @@ ReadOptionFile(
* TK_MAX_PRIO. */
{
const char *realName;
- char *buffer;
+ Tcl_Obj *buffer;
int result, bufferSize;
Tcl_Channel chan;
- Tcl_DString newName, optString;
+ Tcl_DString newName;
/*
* Prevent file system access in a safe interpreter.
@@ -1108,24 +1108,10 @@ ReadOptionFile(
return TCL_ERROR;
}
- /*
- * Compute size of file by seeking to the end of the file. This will
- * overallocate if we are performing CRLF translation.
- */
-
- bufferSize = (int) Tcl_Seek(chan, (Tcl_WideInt) 0, SEEK_END);
- Tcl_Seek(chan, (Tcl_WideInt) 0, SEEK_SET);
-
- if (bufferSize < 0) {
- Tcl_SetObjResult(interp, Tcl_ObjPrintf(
- "error seeking to end of file \"%s\": %s",
- fileName, Tcl_PosixError(interp)));
- Tcl_Close(NULL, chan);
- return TCL_ERROR;
- }
-
- buffer = ckalloc(bufferSize + 1);
- bufferSize = Tcl_Read(chan, buffer, bufferSize);
+ buffer = Tcl_NewObj();
+ Tcl_IncrRefCount(buffer);
+ Tcl_SetChannelOption(NULL, chan, "-encoding", "utf-8");
+ bufferSize = Tcl_ReadChars(chan, buffer, -1, 0);
if (bufferSize < 0) {
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
"error reading file \"%s\": %s",
@@ -1134,18 +1120,8 @@ ReadOptionFile(
return TCL_ERROR;
}
Tcl_Close(NULL, chan);
- buffer[bufferSize] = 0;
- if ((bufferSize>2) && !memcmp(buffer, "\357\273\277", 3)) {
- /* File starts with UTF-8 BOM */
- result = AddFromString(interp, tkwin, buffer+3, priority);
- } else {
- Tcl_DStringInit(&optString);
- Tcl_ExternalToUtfDString(NULL, buffer, bufferSize, &optString);
- result = AddFromString(interp, tkwin, Tcl_DStringValue(&optString),
- priority);
- Tcl_DStringFree(&optString);
- }
- ckfree(buffer);
+ result = AddFromString(interp, tkwin, Tcl_GetString(buffer), priority);
+ Tcl_DecrRefCount(buffer);
return result;
}