summaryrefslogtreecommitdiffstats
path: root/generic/tclEncoding.c
diff options
context:
space:
mode:
authorhobbs <hobbs>2004-03-29 18:49:19 (GMT)
committerhobbs <hobbs>2004-03-29 18:49:19 (GMT)
commitfc35db336cf80ba5d03d87e2d0c86edf1670d8fc (patch)
treece0bae4649cdf08ac4f4a22e22af0af73664e655 /generic/tclEncoding.c
parent8f0d403b02d42ece1a2f24a9bf1327837480fd4e (diff)
downloadtcl-fc35db336cf80ba5d03d87e2d0c86edf1670d8fc.zip
tcl-fc35db336cf80ba5d03d87e2d0c86edf1670d8fc.tar.gz
tcl-fc35db336cf80ba5d03d87e2d0c86edf1670d8fc.tar.bz2
* generic/tclInt.h:
* generic/tclEncoding.c (TclFindEncodings, Tcl_FindExecutable): * mac/tclMacInit.c (TclpInitLibraryPath): Correct handling of UTF * unix/tclUnixInit.c (TclpInitLibraryPath): data that is actually * win/tclWinFile.c (TclpFindExecutable): "clean", allowing the * win/tclWinInit.c (TclpInitLibraryPath): loading of Tcl from paths that contain multi-byte chars on Windows [Bug 920667]
Diffstat (limited to 'generic/tclEncoding.c')
-rw-r--r--generic/tclEncoding.c53
1 files changed, 34 insertions, 19 deletions
diff --git a/generic/tclEncoding.c b/generic/tclEncoding.c
index 7f27ab8..870d587 100644
--- a/generic/tclEncoding.c
+++ b/generic/tclEncoding.c
@@ -8,7 +8,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclEncoding.c,v 1.16.2.2 2003/11/06 21:47:33 hobbs Exp $
+ * RCS: @(#) $Id: tclEncoding.c,v 1.16.2.3 2004/03/29 18:49:35 hobbs Exp $
*/
#include "tclInt.h"
@@ -227,6 +227,7 @@ static int UtfToUtfProc _ANSI_ARGS_((ClientData clientData,
Tcl_EncodingState *statePtr, char *dst, int dstLen,
int *srcReadPtr, int *dstWrotePtr,
int *dstCharsPtr));
+static int TclFindEncodings _ANSI_ARGS_((CONST char *argv0));
/*
@@ -1111,6 +1112,7 @@ Tcl_FindExecutable(argv0)
CONST char *argv0; /* The value of the application's argv[0]
* (native). */
{
+ int mustCleanUtf;
CONST char *name;
Tcl_DString buffer, nameString;
@@ -1129,32 +1131,40 @@ Tcl_FindExecutable(argv0)
/*
* The value returned from TclpNameOfExecutable is a UTF string that
- * is possibly dirty depending on when it was initialized. To assure
- * that the UTF string is a properly encoded native string for this
- * system, convert the UTF string to the default native encoding
- * before the default encoding is initialized. Then, convert it back
- * to UTF after the system encoding is loaded.
+ * is possibly dirty depending on when it was initialized.
+ * TclFindEncodings will indicate whether we must "clean" the UTF (as
+ * reported by the underlying system). To assure that the UTF string
+ * is a properly encoded native string for this system, convert the
+ * UTF string to the default native encoding before the default
+ * encoding is initialized. Then, convert it back to UTF after the
+ * system encoding is loaded.
*/
Tcl_UtfToExternalDString(NULL, name, -1, &buffer);
- TclFindEncodings(argv0);
+ mustCleanUtf = TclFindEncodings(argv0);
/*
* Now it is OK to convert the native string back to UTF and set
* the value of the tclExecutableName.
*/
- Tcl_ExternalToUtfDString(NULL, Tcl_DStringValue(&buffer), -1, &nameString);
- tclExecutableName = (char *)
- ckalloc((unsigned) (Tcl_DStringLength(&nameString) + 1));
- strcpy(tclExecutableName, Tcl_DStringValue(&nameString));
-
+ if (mustCleanUtf) {
+ Tcl_ExternalToUtfDString(NULL, Tcl_DStringValue(&buffer), -1,
+ &nameString);
+ tclExecutableName = (char *)
+ ckalloc((unsigned) (Tcl_DStringLength(&nameString) + 1));
+ strcpy(tclExecutableName, Tcl_DStringValue(&nameString));
+
+ Tcl_DStringFree(&nameString);
+ } else {
+ tclExecutableName = (char *) ckalloc((unsigned) (strlen(name) + 1));
+ strcpy(tclExecutableName, name);
+ }
Tcl_DStringFree(&buffer);
- Tcl_DStringFree(&nameString);
return;
done:
- TclFindEncodings(argv0);
+ (void) TclFindEncodings(argv0);
}
/*
@@ -2813,7 +2823,8 @@ unilen(src)
* assured.
*
* Results:
- * None.
+ * Return result of TclpInitLibraryPath, which reports whether the
+ * path is clean (0) or dirty (1) UTF.
*
* Side effects:
* Varied, see the respective initialization routines.
@@ -2821,11 +2832,13 @@ unilen(src)
*-------------------------------------------------------------------------
*/
-void
+int
TclFindEncodings(argv0)
CONST char *argv0; /* Name of executable from argv[0] to main()
* in native multi-byte encoding. */
{
+ int mustCleanUtf = 0;
+
if (encodingsInitialized == 0) {
/*
* Double check inside the mutex. There may be calls
@@ -2846,7 +2859,7 @@ TclFindEncodings(argv0)
encodingsInitialized = 1;
native = TclpFindExecutable(argv0);
- TclpInitLibraryPath(native);
+ mustCleanUtf = TclpInitLibraryPath(native);
/*
* The library path was set in the TclpInitLibraryPath routine.
@@ -2856,7 +2869,7 @@ TclFindEncodings(argv0)
*/
pathPtr = TclGetLibraryPath();
- if (pathPtr != NULL) {
+ if ((pathPtr != NULL) && mustCleanUtf) {
Tcl_UtfToExternalDString(NULL, Tcl_GetString(pathPtr), -1,
&libPath);
}
@@ -2867,7 +2880,7 @@ TclFindEncodings(argv0)
* Now convert the native string back to UTF.
*/
- if (pathPtr != NULL) {
+ if ((pathPtr != NULL) && mustCleanUtf) {
Tcl_ExternalToUtfDString(NULL, Tcl_DStringValue(&libPath), -1,
&buffer);
pathPtr = Tcl_NewStringObj(Tcl_DStringValue(&buffer), -1);
@@ -2879,4 +2892,6 @@ TclFindEncodings(argv0)
}
TclpInitUnlock();
}
+
+ return mustCleanUtf;
}